当用户在ViewController(A)上的UITableView中选择“行”时,我正在导航到新的ViewController(B)。
如果我在B完成加载之前快速从B按回来,然后立即尝试选择另一行有时,应用程序似乎卡住了。然后它赶上处理多个“行选择”。我想在第一个之后停止选择。
我知道之前已经问过这个问题,建议是UserInteractionEnabled = false。
然而,这似乎不起作用,更重要的是,当用户使用表格导航回View时,我看不到足够好的地方重新打开UserInteractionEnabled。
其他人如何解决这个问题?
我正在使用Xamarin iOS,但我确信这不是特定于Xamarin的问题
答案 0 :(得分:0)
你是对的,防止该方法多次触发的方法之一是禁用表用户交互。
但是,如何重新启用它。这可以在方法将viewcontroller推送到导航堆栈之后完成:
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (tableView.CellAt(indexPath).GetType() == typeof(YourCell)) // For multiple cell types
{
// Disable Interaction on click
tableView.UserInteractionEnabled = false;
// Animate selection
tableView.CellAt(indexPath).SetHighlighted(true, true);
// Load our new viewcontroller
yourNewView myview = AppDelegate.ADSelf.GlobalNavigationController.Storyboard.InstantiateViewController(nameof(yourNewView)) as yourNewView;
AppDelegate.ADSelf.GlobalTabBarController.ShowViewController(myview);
// Enable Interaction on click
tableView.UserInteractionEnabled = true;
}
}
}
如果你问我,那真的是更好的解决方案之一。您可以更进一步,并确保新视图不在导航堆栈上,如果是,则返回。像这样:
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (tableView.CellAt(indexPath).GetType() == typeof(YourCell)) // For multiple cell types
{
// Disable Interaction on click
tableView.UserInteractionEnabled = false;
// Animate selection
tableView.CellAt(indexPath).SetHighlighted(true, true);
// Load our new viewcontroller
yourNewView myview = AppDelegate.ADSelf.GlobalNavigationController.Storyboard.InstantiateViewController(nameof(yourNewView)) as yourNewView;
// Check if it already exists on our stack
if(AppDelegate.ADSelf.GlobalNavigationController.TopViewController.GetType() == typeof(myview)
{
// Enable Interaction on click
tableView.UserInteractionEnabled = true;
return;
}
AppDelegate.ADSelf.GlobalTabBarController.ShowViewController(myview);
// Enable Interaction on click
tableView.UserInteractionEnabled = true;
}
}
}