iphone - UITableView 处于编辑模式 - 'Edit' 按钮不会更改状态

标签 iphone uitableview editmode

我有一个 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

最佳答案

为什么不直接使用UIViewController的-editButtonItem?并重写 -setEditing:animated: 方法。

// Assign the system's edit button, 
// it will change style when different edit status.
self.navigationItem.rightBarButtonItem = self.editButtonItem;

// The editButtonItem will invoke this method.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    if (editing) {
         // Execute tasks for editing status
    } else {
         // Execute tasks for non-editing status.
    }
}

关于iphone - UITableView 处于编辑模式 - 'Edit' 按钮不会更改状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5365074/

相关文章:

iphone - 使用 Transform 正确旋转 UITableView,而无需使用 Interface Builder

c# - 处于编辑模式的单元格不会触发 C# 中的 KeyDown 事件

iPhone SDK : UIBarButtonItem not refreshing after Memory warning

ios - 快速更改 titleTextAttribute

iphone - UIScrollView 中的事件跟踪会阻塞主线程。有修复吗?

iphone - 使用 Storyboard时如何将导航 Controller 推送动画设置为 "No"

ios - 是否可以在 Swift 的 UITableViewCell 中添加 UITableView

ios - UITableViewCell 文本颜色在选择行时发生变化,为什么?

c# - datagridview 自动在新行上开始编辑

Android 在自定义数组适配器中未处于编辑模式时锁定复选框