我有一个自定义 UITableView
允许用户选择多个图像。问题是我的删除方法不起作用。
我跟踪所有选定的图像,当用户确认删除时,图像将从数组中删除并且表格应该更新。
对 [self.tableview reloadData]
的调用并未从我的 tableView 中删除单元格。
我怎样才能做到这一点?怎么调用
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
或类似的东西来强制表格检查数据源并重绘单元格?
最佳答案
看看这个场景,你可以用两种方式执行这件事
1)使用reloadData函数
while using this please make sure about the 2 thing when you choose to delete the cell first check whether that particular record has been deleted at indexpath which you want it to be.
其次,在使用 [self.tableView reloadData] 或 [ObjectofTableView reloadData] 之后从数组中删除数据。这种方式也可以正常工作。
但是苹果已经提供了一些方法来移除表格中的单元格,并且有一些效果。所以下面这种方式用的比较多。
2) 我更喜欢你使用它,因为它在带有 UITableView 的应用程序中看起来很棒。
(void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Over here first delete record from array at indexPath
//[自己makeLogout]; [self.acloginTblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.acloginTblView reloadData];
希望在给我的手指带来如此多的痛苦之后,能以更好的方式解决您的疑问;)
关于iphone - 不删除单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5100067/