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

发布于 2024-12-03 06:25:38 字数 176 浏览 1 评论 0原文

我使用代码将 UINavigationController 的左栏按钮设置为编辑按钮,

leftBarButton = self.editButtonItem;

我想更改其他按钮相对于编辑按钮的单击操作的一些禁用/启用属性。

如何判断编辑按钮是否被按下?

I set my left bar button of UINavigationController as edit button using the code

leftBarButton = self.editButtonItem;

I want to change some disable/enable properties of other buttons with respect to the edit button's click action.

How can i find whether the Edit button is pressed or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

2024-12-10 06:25:38

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

请务必在最后调用 super 实现来管理到编辑视图的其余转换。

The edit button's action sends your view controller the setEditing:animated message. Override this in your subclass to perform other actions when entering or leaving edit mode.

Be sure to call the super implementation at the end to manage the rest of the transition to editing view.

撩发小公举 2024-12-10 06:25:38

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

-(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 按钮的原始行为。

So finally i got the solution...

-(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
    }

}

This method will be called with out changing the original behavior of self.editButtonItem button.

久伴你 2024-12-10 06:25:38

在斯威夫特中:

@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)
}

In Swift:

@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)
}
遇到 2024-12-10 06:25:38

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

  @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.rightBarButtonItem = editButtonItem()
    }

   override func setEditing(editing: Bool, animated: Bool){

        super.setEditing(editing, animated: animated)
        tableView.setEditing(editing, animated: true)


    }

In Swift you can follow the below methods:

  @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.rightBarButtonItem = editButtonItem()
    }

   override func setEditing(editing: Bool, animated: Bool){

        super.setEditing(editing, animated: animated)
        tableView.setEditing(editing, animated: true)


    }
萌酱 2024-12-10 06:25:38
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

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
}

updated:

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

will be called

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文