iphone - 不删除单元格

标签 iphone ios uitableview

我有一个自定义 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/

相关文章:

iphone - 为什么在使用 ASIHTTPRequest 进行调用后,我的 UIScrollView 的框架发生了变化?

iphone - Objective-c iPhone NSTimer 唯一标识符

ios - iOS SLComposeViewController“黑客”

ios - 向 UiTableViewCell 添加删除按钮

ios - TableCell 内的标签未调整大小

iphone - 播放通过自定义协议(protocol)传输的视频(在 iPhone 上)?

ios - 如何在旧的 iOS 设备上使用 ARKit?

ios - 将 Pod 添加到 Xcode 项目会阻碍构建

ios - 如何在单元格中按下按钮时将数据从一个 Tableview 传递到另一个 Tableview?

ios - 添加了 insertRowsAtIndexPaths 的 UITableView 单元格未正确绘制/布局