2013-12-09 129 views
1

我有一个应用程序需要3个用户数据部分:事件的详细信息,事件的位置以及事件的日期/时间。其中的每一个都存储在主视图控制器的一个单元中。我希望能够在需要时删除(使用编辑按钮)每个这些单元格。iOS编辑按钮执行

例如,如果其中一个事件变得无关紧要,我希望用户能够使用编辑按钮删除单元格。我已经列入我的故事板的编辑按钮,如下图所示:

enter image description here

我从来没有学会如何真正落实的编辑按钮,并不能找到如何实际使用的编辑按钮任何苹果文档。是否有代码实现到我的视图控制器将完成此?或者有没有办法实现删除故事板中的单元格?

编辑:这里是我的项目文件,以供参考 - 文件链接删除

回答

2

该应用程序当前正在删除行,并且它似乎在下次装入应用程序时才起作用。你错就错在FinalMasterViewController.m,方法tableView: commitEditingStyle: forRowAtIndexPath有这样的代码:

if (editingStyle == UITableViewCellEditingStyleDelete) { 
[self.managedObjectContext deleteObject:[_fetchedResultsController objectAtIndexPath:indexPath]]; 
} 

您忘记保存

if (editingStyle == UITableViewCellEditingStyleDelete) { 
[self.managedObjectContext deleteObject:[_fetchedResultsController objectAtIndexPath:indexPath]]; 
//THIS IS THE LINE 
[self.managedObjectContext save:nil]; 
//Without it, the context will not save. 
} 
+0

太棒了!谢谢! – Willy2414

1

在你viewWillAppear:方法,设置

[tableview setEditing: NO animated: YES]; 
由按钮调用的方法

然后,拨动

-(void) editClicked{ 
    if(tableview.editing){ 
     [tableview setEditing: NO animated: YES]; 
    else{ 
     [tableview setEditing: YES animated: YES]; 
    } 
} 
+0

试图实现这个代码:遇到错误说“的选择没有已知的类方法” setEditing :animated“。我上面包含了我的项目文件供参考 – Willy2414

+0

我不确定为什么,因为UITableView显然有一个方法:https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITableView_Class/ Reference/Reference.html#// apple_ref/occ/instm/UITableView/setEditing:animated: – erdekhayser

+1

Wait-class method?You sh应该访问tableview对象而不是class。也许[self.tableView setEditing ...将工作? – erdekhayser