如何识别self.editButtonItem按钮的点击事件?

时间:2011-09-07 12:47:43

标签: iphone uinavigationcontroller uinavigationitem

我使用代码

将UINavigationController的左侧栏按钮设置为编辑按钮
leftBarButton = self.editButtonItem;

我想根据编辑按钮的点击操作更改其他按钮的一些禁用/启用属性。

如何找到是否按下了编辑按钮?

5 个答案:

答案 0 :(得分:34)

编辑按钮的操作会向您的视图控制器发送setEditing:animated消息。在子类中重写此项以在进入或退出编辑模式时执行其他操作。

请务必在最后调用super实施,以管理转换到编辑视图的其余部分。

答案 1 :(得分:19)

所以最后我得到了解决方案......

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];

    if(editing) {
        //Do something for edit mode
    }

    else {
        //Do something for non-edit mode
    }

}

调用此方法时不会更改self.editButtonItem按钮的原始行为。

答案 2 :(得分:7)

在斯威夫特:

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

   ....
    self.navigationItem.leftBarButtonItem = self.editButtonItem()
}

override func setEditing(editing: Bool, animated: Bool) {
    // Toggles the edit button state
    super.setEditing(editing, animated: animated)
    // Toggles the actual editing actions appearing on a table view
    tableView.setEditing(editing, animated: true)
}

答案 3 :(得分:3)

在Swift中,您可以按照以下方法操作:

df -m -P $PWD| awk {'print $4'}

答案 4 :(得分:1)

UIBarButtonItem *barBut=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(doSomething)];


self.navigationItem.leftBarButtonItem=barBut;

[barBut release];


.h
-(void)doSomething;

.m 

-(void)doSomething{

    NSLog(@"dooooooooooooo");
        //ur stuff
}

更新

 - (void)setEditing:(BOOL)editing animated:(BOOL)animated 

将被称为

editButtonItem

Returns a bar button item that toggles its title and associated state between Edit and Done.

- (UIBarButtonItem *)editButtonItem

Discussion
If one of the custom views of the navigationItem property is set to the returned object, the associated navigation bar displays an Edit button if editing is NO and a Done button if editing is YES. The default button action invokes the setEditing:animated: method.

    Availability
    Available in iOS 2.0 and later.

    See Also
    @property editing

    – setEditing:animated:


    Declared In
    UIViewController.h

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html