UINavigationController后退按钮动作问题
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有可能按下了第二个视图控制器两次。当您同时推送视图控制器的多个实例时,您不会看到推送动画有任何差异。看起来只有一个控制器被推动。这是因为您在上一个视图控制器完全推送之前推送了下一个视图控制器。
如果您按下第二个视图控制器两次,请检查您的代码。
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.