【问题标题】:Simultaneous push ViewController同时推送 ViewController
【发布时间】:2013-12-18 15:42:59
【问题描述】:

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

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

这是简单的示例代码
' -(void)viewDidLoad { [超级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];


}`

【问题讨论】:

  • 对 FirstViewController 使用 initwithNibName
  • 嗯,肯定不是这个问题
  • 如果同时按下两个按钮,您希望发生什么?您可以推送一个视图控制器或另一个,但是“同时”推送两个视图控制器意味着什么?
  • 在 xcode4 中只推送了一个 VC。
  • 也许我误解了你所追求的,但似乎你正在寻找的是类似 [BTN1 setExclusiveTouch:YES];和 [BTN2 setExclusiveTouch:YES];这只会阻止两个按钮同时触发。

标签: ios xcode4 uinavigationcontroller ios7 xcode5


【解决方案1】:

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

[yourButton setExclusiveTouch:YES]; 

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      相关资源
      最近更新 更多