当没有更多要删除的单元格时,如何在UITableView中关闭编辑模式?

can*_*boy 18 iphone objective-c uitableview ios

我已经尝试将它放在我的代码的各个部分,比如在commitEditingStyle方法的末尾,但我无法让它停止编辑模式.基本上,我想在没有更多单元格的情况下自动退出编辑模式...

if ([self.tableView numberOfRowsInSection:0] ==0)
    {
        NSLog(@"this triggers, but doesn't stop editing..");
        self.tableView.editing = NO;
        [self.tableView endEditing:YES];
    }
Run Code Online (Sandbox Code Playgroud)

Aec*_*Liu 37

怎么样[self setEditing:NO animated:YES]?我想self是UITableViewController的一个实例.


too*_*ser 10

来自苹果文档:

Note: The data source should not call setEditing:animated: from within its implementation of tableView:commitEditingStyle:forRowAtIndexPath:. If for some reason it must, it should invoke it after a delay by using the performSelector:withObject:afterDelay: method.

因此,在内部调用它commitEditingStyle并不是一个好习惯.

  • 老式的方式,第一次搞砸了! (2认同)

Ben*_*oît 5

如果不是[self setEditing:NO animated:YES]吗?