[英]Xcode iOS UITableView Insert New Cell Animation
提前致謝。 我正在處理一個分為不同部分的UITableView。 用戶只能從特定部分添加或刪除單元格。 UITableView中顯示的信息存儲在一個數組中,其中每個對象代表一個部分:
例如:tableItemsArray =(((arrayForSection1),(arrayForSection2),(arrayForSection3))
我設置了動畫來處理刪除,如下所示:
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationRight];
然后,我以編程方式從數組中刪除該項目,以將其從數據模型中刪除。 但是,我在如何以動畫形式插入單元格時遇到困難。
目前,我正在運行當前的偽算法:
更新資料
將新項目添加到數組時,它將存儲在字符串中以保留新項目的記錄。 訴諸數組后,我將遍歷單元格數組以找到其indexPath,然后刪除字符串(以防止遞歸插入動畫)並執行動畫,但是代碼不會對其插入表的動畫進行動畫處理。 我想知道動畫代碼(如下所示)是否不起作用,因為我正在使用[tableView reloadData]?
// For Each Section in the table:
for (NSMutableArray *object in sectionsInTable) {
// For Each Cell in a section (Cells are stored in an array in index 1)
for (NSString *label in [object objectAtIndex:1]) {
if ([label isEqualToString:_insertedObject]) {
// New item
_insertedObject = Nil;
// animate addition
[self.labelListTableView beginUpdates];
[self.labelListTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[[object objectAtIndex:1] indexOfObject:label] inSection:[sectionsInTable indexOfObject:object]]] withRowAnimation:UITableViewRowAnimationBottom];
[self.labelListTableView endUpdates];
}
}
}
有什么想法為什么動畫不起作用?
謝謝
d
似乎[tableView reloadData]正在阻止動畫。
// Annimate the new Item
// For Each Section in the table:
for (NSMutableArray *object in sectionsInTable) {
// For Each Cell in a section:
for (NSString *cell in [object objectAtIndex:1]) {
if ([cell isEqualToString:_insertedObject]) {
// New item
_insertedObject = Nil;
// animate addition
[tableView beginUpdates];
NSInteger section = [sectionsInTable indexOfObjectIdenticalTo:object];
NSInteger row = [[object objectAtIndex:1] indexOfObjectIdenticalTo:cell];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
[tableView insertRowsAtIndexPaths: [NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationBottom ];
[tableView endUpdates];
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.