更改按钮标题是否会阻止进一步的操作? [英] Does changing a button's title prevent further action?

查看:62
本文介绍了更改按钮标题是否会阻止进一步的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长条按钮,我们称之为按钮1,单击该按钮时,会以编程方式将其切换到其他页面。

但是,单击另一个按钮(按钮2)后,按钮1的标题会更改。

I have a bar button, let's call it button 1, which when clicked, programatically segues to a different page.
However, after clicking another button (button 2), button 1's title is changed.

此后,无论是否再次单击按钮2更改标题,按钮1都不再响应。

From then on, button 1 no longer responds regardless of whether it's title has been changed back by clicking button 2 again.

我希望你能理解,如果不是的话-我可以澄清

I hope you understand, if not - I can clarify

代码:(按钮2为编辑状态)-(1为信息/添加)

code: (button 2 is edit) - (1 is info/add)

-(void)editButton:(id)sender 
{
    [self setEditing:(![self isEditing])];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                                                                              style: UIBarButtonItemStylePlain 
                                                                             target:self 
                                                                             action:@selector(edit:)];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" 
                                                                              style: UIBarButtonItemStylePlain 
                                                                             target:self 
                                                                             action:@selector(infoToAdd:)];
}

-(void) edit:(UIBarButtonItem *) barBtnItem
{
    // if not editing
    if (![self isEditing]) {
        [self setEditing:YES];
        [self.navigationItem.rightBarButtonItem setTitle:@"Done"];
        [self.navigationItem.leftBarButtonItem setTitle:@"Add"];
    } else {
        [self setEditing:NO];
        [self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
        [self.navigationItem.leftBarButtonItem setTitle:@"Info"];
    }
}

-(void) infoToAdd:(UIBarButtonItem *) barBtnItem
{
    // if not editing
    if (![self isEditing]) {
        [self.navigationItem.leftBarButtonItem setTitle:@"Info"];
    } else {
        [self.navigationItem.leftBarButtonItem setTitle:@"Add"];
    }
}    

-(void)infoAddButton:(id)sender
{
    if (self.tableView.isEditing) {
        [self performSegueWithIdentifier:@"segueToAdd" sender:self];
    } else {
        [self performSegueWithIdentifier:@"segueToInfo" sender:self];
    }
}

编辑:

在更改按钮的标题后,按下按钮似乎没有调用'infoAddButton'函数(我使用了断点)。

It seems the function 'infoAddButton' is not even getting called (I used a breakpoint) when I press the button, after changing it's title.

推荐答案

我认为这对您有所帮助。这里只解释左按钮,您可以为右按钮实现相同的逻辑

i think this is help you. here explain only left button same logic you can implement for right button

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(dosomeTask:)];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"show" style:UIBarButtonItemStyleBordered target:self action:@selector(dosomeTask1:)];

isValid是布尔类型。因此最初在您的viewDidLoad中设置NO

isValid is a Bool type. so initially in your viewDidLoad set NO

-(void)dosomeTask:(id)sender{

    if (isValid) {
          self.navigationItem.leftBarButtonItem.title=@"Menu";
        isValid=NO;

        [self infomationShow];


    }else{
         self.navigationItem.leftBarButtonItem.title=@"show";
        isValid=YES;
        [self menuController];

    }

}

-(void)menuController{

     NSLog(@"menu");

}

-(void)infomationShow{

     NSLog(@"infomationShow");
}

这篇关于更改按钮标题是否会阻止进一步的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆