我研究Apple示例代码Lister,我重写程序(删除容器组和cloudListCoordinator
,documentMenu
,userActivity
,只使用localDocument
存储文件),它的工作方式相同,但我有两个自定义UITableViewCell
的问题,一个是listColorCell
,另一个是listItemCell
,我覆盖了setEditing
方法{ {1}}与Apple的示例代码相同,当我按下编辑按钮时,第一行中的TableViewController
显示,下面是listColorCell
,如果我不触摸或更改listItemCell
的当前颜色,当我按下完成按钮时,它可以退出编辑模式。
所以问题仅在于我触摸listItem
并且这会使listColorCell
颜色发生变化,然后再次按下完成按钮,listItemCell's
和ListColorCell
似乎没有退出编辑模式。我查看故事板的插座和内容视图,使用穴居人调试,仍然无法找到可能出错的地方。
1.首先,listItem的颜色为蓝色
2.然后我按ListItemCell
上的红色colorView
,ListColorCell
颜色变为红色
3.但是当我再次按下完成按钮时,会发生这种情况。
我是新来的,希望有人可以帮助我..
答案 0 :(得分:0)
只是一个建议,检查您的控制器是否符合这些要求:
我使用通常的UIViewController,它工作正常 - 你需要:
让您的控制器成为UITableViewDelegate, UITableViewDataSource
的代表
实施
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
programmatically add EDIT button - self.navigationItem.rightBarButtonItem = self.editButtonItem
(如果您从构建器添加EDIT按钮,则需要手动调用setEditing:YES)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:YES];
}
- (void)tableView
:(UITableView *)tableView didSelectRowAtIndexPath
:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
// do not forget interface in header file
@interface ContactsController : ViewController<
UITableViewDelegate,
UITableViewDataSource>
我在这里给出了Objective-C代码,您可以参考它,或者您可以转换为swift并尝试