更改按钮标题是否会阻止进一步操作?

时间:2014-02-04 11:09:15

标签: ios cocoa-touch uibarbuttonitem

我有一个条形按钮,我们称之为按钮1,单击该按钮时,以编程方式将其切换到不同的页面。
但是,在单击另一个按钮(按钮2)后,按钮1的标题会被更改。

从那时起,按钮1不再响应,无论是否通过再次单击按钮2更改了标题。

我希望你理解,如果没有 - 我可以澄清

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

-(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'甚至没有被调用(我使用断点)。

1 个答案:

答案 0 :(得分:1)

我认为这对你很有帮助。这里只解释左键与右键相同的逻辑

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是Bool类型。所以最初在你的viewDidLoad中设置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");
}