我在我的应用中使用UITableView
,点按时会使用UINavigationController
将另一个视图控制器推送到导航控制器的视图控制器堆栈。
然而,当tableview上的一个单元格被双重†时,tableView:didSelectRowAtIndexPath:
被称为两次,导致导航控制器将两个新的viewcontroller推入堆栈并导致以下控制台输出:
nested pop animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
这不是一个非常重要的问题,因为用户不太可能对表格视图单元格进行双击,但是我想知道是否有一种优雅的解决方案可以防止这种误导? (也许检查导航控制器的topViewController
,然后决定是否应该实际执行推送pushViewController:
方法?)。
答案 0 :(得分:12)
只需将userInteractionEnabled
设置为NO
,就像这样
在viewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
// if you return from another viewController
[tableView setUserinteractionEnabled:YES];
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// do your logic here and at the end just set user interaction to NO
[tableView setUserInteractionEnabled:NO];
}
这将阻止所有用户与您的tableview进行互动。
答案 1 :(得分:9)
这是一行解决方案
self.tableView.multipleTouchEnabled = NO;
答案 2 :(得分:7)
我发现此处描述的问题的解决方法是将所有didSelectRowAtIndexPath代码包装在以下检查中:
<h1>The Rock Paper Scissors Game</h1><br>
<p>YAAAAY!</p>
这将检查是否已将另一个视图控制器推送到视图控制器堆栈的顶部(并且仍在等待由于某种原因实际出现在屏幕上)。
我相信其他地方提到的multiTouchEnabled属性实际上是指多点触控功能,它允许iOS同时注册多个触摸事件(例如,同时使用两个手指在屏幕上进行双指缩放)而不是多次顺序接触。
答案 3 :(得分:6)
乔丹索伦森现代化迅速:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if self.navigationController?.topViewController == self
{
self.performSegueWithIdentifier("whatever", sender:self)
}
else{
// uncomment to break in else case print("fasttaper's superfluous input was ignored")
}
}
答案 4 :(得分:0)
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if self.navigationController?.topViewController == self
{
return true
}
else{
return false
}
}
禁用手机上的多重触控
答案 5 :(得分:-1)