navigationController popViewControllerAnimated不起作用

时间:2015-02-21 08:44:36

标签: ios objective-c

我是ios开发的新手,我想在我的应用中添加后退按钮。 为此,我在-(view)didLoad中编写代码:

UIButton *btnbarBack = [UIButton buttonWithType:UIButtonTypeCustom];
btnbarBack.frame = CGRectMake(0, 0, 30, 22);
[btnbarBack setImage:[UIImage imageNamed:@"arrow_left.png"] forState:UIControlStateNormal];
[btnbarBack addTarget:self action:@selector(OnClick_btnBack:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *btnbarBack_1 = [[UIBarButtonItem alloc] initWithCustomView:btnbarBack];

self.navigationItem.rightBarButtonItem = btnbarBack_1;

我使用popViewController返回 Clickevent代码是:

-(IBAction)OnClick_btnBack:(id)sender  {
    [self.navigationController popViewControllerAnimated:YES];
}

但是当我点击按钮事件时会发生火灾,但不会出现任何变化!

我已经尝试过:

-[self.navigationController pushViewController:self.navigationController.parentViewController animated:YES];

-[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];

-[self dismissViewControllerAnimated:YES completion:nil];

但这3个也不起作用。有没有其他选择来解决这个问题。

1 个答案:

答案 0 :(得分:0)

看起来您正在重新创建故事板中已有的按钮。如果不是,则表示您在故事板中连接了IBAction。将括号中的“IBAction”更改为“void”,这应该可以修复它。

另外......为什么不用自定义方法创建Uibarbutton并在那里设置图像?

相关问题