UITableView 处于编辑模式 - “编辑”按钮不会改变状态
我有一个 UIViewController 类,带有一个 tableView。在 viewDidLoad 中:
UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemEdit
target:self
action:@selector(toggleEditMode)] autorelease];
在方法 'toggleEditMode' 中:
-(void)toggleEditMode{
if(self.theTable.editing) {
[theTable setEditing:NO animated:YES];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else if ([callsArray count]!=0){
[theTable setEditing:YES animated:YES];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
问题是“编辑”按钮不会更改为“完成”。缺少什么?我已经声明了所有方法:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
谢谢,
RL
I have a UIViewController class, with a tableView. In viewDidLoad:
UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemEdit
target:self
action:@selector(toggleEditMode)] autorelease];
In te method 'toggleEditMode':
-(void)toggleEditMode{
if(self.theTable.editing) {
[theTable setEditing:NO animated:YES];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else if ([callsArray count]!=0){
[theTable setEditing:YES animated:YES];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
The problem is that the Edit button does not change do 'DONE'. What's missing? I have all the methods declared:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Thanks,
RL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不直接使用 UIViewController 的
-editButtonItem
?并重写-setEditing:animated:
方法。Why not use
-editButtonItem
of UIViewController directly ? And override-setEditing:animated:
method.这是因为当您切换模式时,您仅设置按钮的样式(而不是其文本)。您需要执行此操作(或等效操作):
It's because you're only setting the style of the button (not its text) when you switch modes. You need to do this (or equivalent):
您确定 callsArray 不为空吗?
在
toggleEditMode
内放置一个断点,看看会发生什么。编辑
好的,在了解你的问题后,看看这个线程
You sure
callsArray
is not empty ?Place a breakpoint inside
toggleEditMode
and see what happens there.Edit
Ok, after understanding your question, have a look at this thread