1

我已经按照我在网上找到的信息进行了操作,并且我设法显示了该按钮,但是当我单击它时,什么也没有发生。我是 iOS 编程新手,我不确定我是否做错了什么。

UIImage *backImage = [UIImage imageNamed:@"backIcon.PNG"];
// create the button and assign the image to the button
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backImage.size.width, backImage.size.height);

[backButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = customBarButton;

这个按钮的代码

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

谢谢

4

1 回答 1

0

首先,您不必隐藏后退按钮,因为您要添加自己的按钮,其次尝试将按钮目标替换为以下内容:

[backButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];

编辑:

在故事板中使用 navigationController 的正确方法如下:

1- 添加一个 UInavigationController。

2-添加rootViewController关系到第一个 VC1。

3-添加push从VC1到VC2的segue。

这样您就可以正确地推送和弹出您的 VC2。

请考虑阅读教程以更好地理解故事板、转场和导航。

于 2013-10-23T05:01:55.157 回答