编辑模式下的UITableView

编辑模式下的UITableView

本文介绍了编辑模式下的UITableView - “编辑”按钮不会更改状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有tableView的UIViewController类。在viewDidLoad中:

I have a UIViewController class, with a tableView. In viewDidLoad:

UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemEdit
                    target:self
                    action:@selector(toggleEditMode)] autorelease];

在te方法'toggleEditMode'中:

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

谢谢,

RL

推荐答案

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

Why not use -editButtonItem of UIViewController directly ? And override -setEditing:animated: method.

// 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.
    }
}

这篇关于编辑模式下的UITableView - “编辑”按钮不会更改状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:26