【问题标题】:Xcode Not Using NSMutableArray on Table CellsXcode 不在表格单元格上使用 NSMutableArray
【发布时间】:2013-07-04 04:35:57
【问题描述】:

我正在构建一个使用表格单元格的 iPhone 应用程序。我设置此代码以尝试从表中删除单元格,但它似乎不起作用,因为我没有使用 NSMutableArray。当我滑动时,我得到了删除按钮,但删除按钮没有做任何事情。我的问题是,如果我没有将 NSMutableArray 与我的表格单元格一起使用,这行:[self.dataArray removeObjectAtIndex:indexPath.row]; 可以工作吗?

使用的代码

(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES; }
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //remove the deleted object from your data source.
        //If your data source is an NSMutableArray, do this
        [self.dataArray removeObjectAtIndex:indexPath.row];
    } }

【问题讨论】:

    标签: ios xcode uitableview cocoa-touch cell


    【解决方案1】:

    这里是苹果文档的表视图编程指南的链接。 Table view programming guide 它有一个使用NSArray 的简单委托方法,并有一个可用于删除和插入的示例代码。您上面显示的代码缺少委托部分以执行删除。看看清单 7.3,这可能是您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 2014-11-17
      • 2023-03-14
      • 2011-03-15
      • 2020-09-30
      • 1970-01-01
      相关资源
      最近更新 更多