[英]UITableView with multiple sections : section with 1 row, deleting the row crashes the app
[英]Deleting multiple table view sections with individual animations for each section
就像iPhone“設置”應用中的“ Wi-Fi”一樣,我有一個表格視圖,其中第一部分的開關可切換是否顯示以下部分。
更新tableView: numberOfRowsInSection:
之后,通過使用insertSections: withRowAnimation:
和deleteSections: withRowAnimation:
我使它成功運行。 但是,與“設置”中的“ Wi-Fi”不同,所有刪除的部分在消失之前會一起折疊。
我想實現在“無線網絡連接”,在那里它們被從視圖中刪除個別內時,自己的部分崩潰同樣的效果。
推薦的方法是什么?
我能夠做到這deleteSections
每節調用deleteSections
:
static int nos = 4;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return nos;
}
-(IBAction)onFadeTableButton:(id)sender
{
NSMutableIndexSet *sectionsToDelete = [NSMutableIndexSet indexSet];
[sectionsToDelete addIndex:3];
nos = 3;
[self.tableView deleteSections:sectionsToDelete
withRowAnimation:UITableViewRowAnimationTop];
[sectionsToDelete addIndex:2];
[sectionsToDelete removeIndex:3];
nos = 2;
[self.tableView deleteSections:sectionsToDelete
withRowAnimation:UITableViewRowAnimationMiddle];
[sectionsToDelete addIndex:1];
[sectionsToDelete removeIndex:2];
nos = 1;
[self.tableView deleteSections:sectionsToDelete
withRowAnimation:UITableViewRowAnimationMiddle];
[sectionsToDelete addIndex:0];
[sectionsToDelete removeIndex:1];
nos = 0;
[self.tableView deleteSections:sectionsToDelete
withRowAnimation:UITableViewRowAnimationMiddle];
}
代碼很丑陋,因為我很快就使用了一個現有項目(包含4個部分的表視圖),但是這個想法必須明確。 請不要按原樣使用它,請使其美觀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.