Xcode不在表格单元格上使用NSMutableArray

时间:2013-07-06 04:27:28

标签: ios xcode uitableview cocoa-touch cell

我正在构建一个使用表格单元格的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];
    } }

1 个答案:

答案 0 :(得分:1)

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