我是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个也不起作用。还有没有别的办法来解决这个问题。
发布于 2015-02-21 21:32:57
看起来您正在重新创建一个已存在于情节提要中的按钮。如果不是,则说明您已将IBAction连接到情节提要中的某个内容。将括号中的"IBAction“更改为"void”,这样应该可以修复它。
Also...why不是用自定义方法创建Uibarbutton并在其中设置图像吗?
https://stackoverflow.com/questions/28643856
复制相似问题