表格视图包含在常规视图中
正如预期的那样,点击“编辑”按钮(在该表格视图中)为每一行显示“带负号的红点”(即方法“setEditing”执行正常)。
但是,单击此红点不会显示相应的“删除”按钮('commitEditingStyle'不会执行)。
任何可能出错的想法(参见下面的相关代码)?
//---- RootViewController.h ----
@interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate> { //used to be a 'UITableViewController'. Changed to UIViewController and rewired so I could add an iAd banner and the tableView to it. Before that change, issue was not present (commitEditingStyle below used to work).
...
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
//----- RootViewController.m ----
- (void)viewDidLoad {
self.navigationItem.leftBarButtonItem = self.editButtonItem;
...
}
- (void) setEditing:(BOOL)editing animated:(BOOL)animated { //Added so clicking 'Edit' displays red dots that rotate on tap (as expected).
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
if (editing) {
NSLog(@"RootViewController setEditing"); //Executes OK.
}
}
- (void)tableView:(UITableView *)tableView //Clicking a red dot no longer executes this method (so, does not display 'Delete' red button).
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"RootViewController commitEditingStyle"); //Does NOT execute.
...
}
答案 0 :(得分:0)
仔细检查您是否已将表UITableViewDelegate
和UITableViewDataSource
正确连接到您编写的新UIViewController上。
答案 1 :(得分:0)
确保将cell.editingAccessoryView
设置为nil:
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
cell.editingAccessoryView = nil;
}
答案 2 :(得分:0)
你没有在.h中实现tableView协议..你的类界面应该是这样的
@interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate, UITableViewDelegate,UITableViewDataSource>