【发布时间】:2015-09-25 14:43:39
【问题描述】:
我的UIViewController 中显示了UIButton。这个按钮通过xib(touchUpInside)绑定到下面的IBAction
- (IBAction)messagesButtonPressed:(id)sender {
ChatsViewController* chatsVC = [[ChatsViewController alloc] initWithNibName:@"ChatsViewController" bundle:nil];
[self.navigationController pushViewController:chatsVC animated:YES];
}
我注意到,在临时挂起 UI 的登录操作期间,如果用户重复单击此按钮,则在登录操作完成时会触发 TWICE。这会导致以下情况:
nested push animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
此外,当我从这个视图返回时,我最终会在同一页面上看到一个可见的状态/导航栏和一个黑色的内容区域。此时再次单击返回按钮会导致崩溃。
据我了解,iOS 在无响应期间排队交互,这可能是导致此行为的原因。我添加的解决方法只是在 IBAction 中禁用用户交互并在 viewWillAppear 中重新启用。例如
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// ...
[self.messagesButton setUserInteractionEnabled:YES];
}
- (IBAction)messagesButtonPressed:(id)sender {
[self.messagesButton setUserInteractionEnabled:NO];
ChatsViewController* chatsVC = [[ChatsViewController alloc] initWithNibName:@"ChatsViewController" bundle:nil];
[self.navigationController pushViewController:chatsVC animated:YES];
}
有没有更安全的方法来防止这种多点触控?
编辑:我应该提到我已经尝试启用 ExclusiveTouch,并且在登录完成后也无法重现此问题,并且无论我多快按下此按钮,UI 都会恢复正常。
【问题讨论】:
标签: ios objective-c uibutton ibaction