我有一个快速的 TableView / Collection View 。无论如何,我可以将项目附加到容器的末尾吗?比如颠倒的堆栈之类的?
最佳答案
您需要在 UITableView 和 Collection View 中插入行,因为首先需要在您的数据源中插入行。 对于 TableView
//Update data source with the object that you need to add
[tableDataSource addObject:newObject];
NSInteger row = [tableDataSource count]-1 ;//specify a row where you need to add new row in your case last
NSInteger section = //specify the section where the new row to be added,
//section = 0 here since you need to add row at first section
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
对于 Collection View
[self.myCollectionView performBatchUpdates:^{
[collectionDataSource addObject:newObject];
NSInteger row = [collectionDataSource count]-1 ;//specify a row where you need to add new row in your case last
to add new row in your case last
NSInteger section = //specify the section where the new row to be added,
//section = 0 here since you need to add row at first section
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self.myCollectionView insertItemsAtIndexPath: indexPath];
} completion:nil];
关于ios - 如何将项目追加到表格或 Collection View 的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32863439/