UINavigationController后退按钮动作问题

发布于 2024-12-06 17:02:38 字数 1401 浏览 0 评论 0原文

我有一个 UINavigationController,第一个视图是 UIView。我设置了两个按钮,每个按钮都推动另一个视图,都是 UITableViewController。 第一个按钮工作得很好。问题是:当我在第二个 TableViewController 中并点击后退按钮时,它会尝试再次推送视图,并且只有第二次它才会返回主视图。 我还有一个 UITabBarController 设置,我注意到,如果我在第一个选项卡中(主视图有两个按钮推动两个表格视图,恰好在第二个视图中),我点击另一个选项卡,然后点击第一个选项卡 - 它显示我的第一个 UITableViewController 的内容,当我点击返回时,它显示第二个 UITableViewController (应该显示),只有第二次点击它才会转到主视图。

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

- (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 中的后退按钮设置相同并且工作正常......可能是什么问题?

我刚刚添加了另一个 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];  
}

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

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2024-12-13 17:02:39

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文