UINavigationController后退按钮动作问题 [英] UINavigationController back button action problem

查看:40
本文介绍了UINavigationController后退按钮动作问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UINavigationController,第一个视图是UIView.我设置了两个按钮,每个按钮都按下了另一个视图,两个都是UITableViewControllers.第一个按钮可以正常工作.问题是:当我进入第二个TableViewController并点击后退按钮时,它将尝试再次推送视图,并且仅第二次返回主视图.我也有一个UITabBarController设置,我注意到,如果我在第一个选项卡(主视图中有两个按钮同时按下两个表视图和第二个视图中的两个按钮),然后点击另一个选项卡,然后再次点击第一个选项卡-它向我显示了我的第一个UITableViewController的内容,当我点按它时,它显示了第二个UITableViewController(应该显示),只有第二次点击时,它才进入主视图.

I have an UINavigationController and the first view is an UIView. I've setup two buttons and each one pushes another view , both UITableViewControllers. The first buttons works just fine. The problem is: when I'm in the second TableViewController and I tap on the back button it tries to push the view again and only the second time it goes back to the Main View. I also have an UITabBarController setup and I noticed that if I am in my first tab(the Main View with the two buttons pushing the two tableviews and precisely in the second view ) and i tap on another tab then tap back on the first - it shows me the content of my first UITableViewController and when I tap back it shows the second UITableViewController(that is supposed to be displayed) and only the second time i tap it goes to the Main View.

我不知道我刚才所说的内容是否可以理解,这也是返回按钮的代码及其操作:

I don't know if it's understandable what I just said, here is also the code for the back button and the action for it:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *back= [UIButton buttonWithType:UIButtonTypeCustom];  
    UIImage *backImage = [[UIImage imageNamed:@"backb.png"]  
                          stretchableImageWithLeftCapWidth:10 topCapHeight:10];  
    [back setBackgroundImage:backImage forState:UIControlStateNormal];  
    [back addTarget:self action:@selector(cancel:)  
   forControlEvents:UIControlEventTouchUpInside];  
    back.frame = CGRectMake(0, 0, 37, 26);  
    UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc]  
                                      initWithCustomView:back] autorelease];  
    self.navigationItem.leftBarButtonItem = cancelButton;
}


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

第一个UITableViewController中的后退按钮设置相同,并且工作正常……这可能是问题所在吗?

The back button in the first UITableViewController is setup the same and works just fine...what could be the problem?

我刚刚添加了另一个UITableViewController,显然现在当我进入第三个视图时,我尝试返回主视图,它将加载两次视图,并在返回之前加载第一个UITableViewController ...

I've just added another UITableViewController and obviously now when I'm in the third view and I try to go back to the Main View it loads the view two times and the first UITableViewController before it goes back...

推荐答案

您有可能两次按下第二个视图控制器.当您同时推送视图控制器的多个实例时,推送动画不会有任何区别.看起来只有一个控制器被推入.这是因为您在完全推上前一个视图控制器之前先推了下一个视图控制器.

There are chances that you have pushed the second view controller twice. While you push multiple instances of view controllers at the same time, you won't see any difference in the pushing animation. It'd look like only one controller is being pushed. This is because you push the next view controller before the previous view controller was pushed completely.

如果您两次按下第二个视图控制器,请检查您的代码.

Check your code if you are pushing the second view controller twice.

这篇关于UINavigationController后退按钮动作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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