iphone - 从具有多个部分的 UITableView 中删除行

标签 iphone ios uitableview syntax

我正在开发一个 iPad 应用程序,其中一个屏幕有一个包含多个部分的嵌入式表格 View 。每个部分都由其自己的数组(array1 和 array2)填充。

我创建了一个按钮,将此表置于编辑模式。但是,我需要改变我的

$tableView:commitEditingStyle:forRowAtIndexPath

以某种方式确定所选行位于哪个部分,并从关联数组中删除该条目。有人有什么想法吗?

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if(editingStyle == UITableViewCellEditingStyleDelete){     
//This is the line i need to change...
        [array1 removeObjectAtIndex:indexPath.row];
        [myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

最佳答案

看起来您需要从正确的数组中删除该行...在这些部分上使用 switch 语句可能会起作用(但前提是有一定数量的部分,您似乎表明有)

因此,在从数组中删除对象的地方,请确保根据该部分从正确的数组中删除它。

  switch (indexPath.section) {
    case 0
      [array0 removeObjectAtIndex:indexPath.row];
      break;
    case 1
      [array1 removeObjectAtIndex:indexPath.row];
      break;
  }

等等

关于iphone - 从具有多个部分的 UITableView 中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6469323/

相关文章:

iphone - 带iOS 6模拟器的iPhone的模拟器屏幕尺寸

iphone - 创建一个 UINavigationController 以在没有 Interface Builder 的 UITableViewController 中使用

android - AppStore 中有新版本时如何更新基于 Cordova 的应用程序?

ios - iPad 中 UITableView 中的 CALayer setCornerRadius 滞后?

iphone - 在构建表格时如何在 UITableViewController 中显示 View ?

iphone - 如何在绘图前不清除上下文

iphone - 如何控制 iPhone 上的网络事件指示器

iphone - iPhone:请求cellforrow以获取超出范围的行

ios - 如何在 iOS 本地化文件中添加上标字符串

ios - 如何在 Interface Builder 中将 UITableViewCell 的内容 View 转换为普通的 UIView?