同时推送ViewController

时间:2013-12-02 19:55:09

标签: ios xcode4 uinavigationcontroller ios7 xcode5

我对xcode5和新的sdk有一个“奇怪”的问题。 我有一个导航控制器。 根视图控制器有2个按钮,两个按钮都链接到将视图控制器推入导航控制器堆栈的操作。 如果我在XCode5上运行这个项目,并且如果我同时按下两个按钮,导航控制器就会发出“疯狂”的消息:“嵌套推送动画可能导致导航栏损坏”。

但是如果我用xCode4尝试相同的代码,那么如果我同时推送,应用程序也会工作。 我忘记了什么吗? 这是一个众所周知的行为吗? 有办法解决这个问题吗? 非常感谢

这是简单的示例代码
“      - (无效)viewDidLoad中   {     [super viewDidLoad];

UIButton *BTN1= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BTN1 addTarget:self action:@selector(ACTION) forControlEvents:UIControlEventTouchUpInside];
[BTN1 setTitle:@"XXX" forState:UIControlStateNormal];
[BTN1 setFrame:CGRectMake(0, 100, 100, 100)];


UIButton *BTN2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BTN2 addTarget:self action:@selector(ACTION) forControlEvents:UIControlEventTouchUpInside];
[BTN2 setFrame:CGRectMake(0, 200, 100, 100)];
[BTN2 setTitle:@"XXX" forState:UIControlStateNormal];
[self.view addSubview:BTN1];
[self.view addSubview:BTN2];

}



-(void)ACTION
{
FirstViewController *fi = [[FirstViewController alloc] init];
[self.navigationController pushViewController:fi animated:YES];


}`

2 个答案:

答案 0 :(得分:4)

为防止同时按下2个按钮导致导航堆栈损坏,最好为您正在使用的按钮设置独占触摸。这样,您可以阻止按钮操作的多个触发器,并防止多个ViewControllers被推送到堆栈并发生损坏。

[yourButton setExclusiveTouch:YES]; 

答案 1 :(得分:0)

使用 button.exclusiveTouch = YES ;在每个按钮上。 您需要将它们连接到UIButtons并在viewDidLoad中设置属性。

相关问题