我有一个带有几个单元格的UITableView,每当我按下其中一个单元格时,我想要转到另一个屏幕。我的代码工作,有点....但有时我会推动细胞两次以便塞!
有谁知道为什么?
func tableView(gamesListTableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (indexPath.row < GamesList.count) {
self.gameState = GamesList[indexPath.row];
performSegueWithIdentifier("presentGame", sender: self);
} else {
let alert = UIAlertController(title: "Swipe!", message: "Swipe Invite To The Left", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: "OK!", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in }
alert.addAction(alertAction)
presentViewController(alert, animated: true) { () -> Void in }
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "presentGame") {
var presentGame = segue.destinationViewController as! Game;
presentGame.gameState = self.gameState;
}
}
答案 0 :(得分:1)
野外存在一个已知的问题,需要使用虚拟dispatch_async调用作为解决方法 - http://openradar.appspot.com/19563577可能在将来的版本中它会消失。以下是具有变通方法的代码的外观:
func tableView(gamesListTableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (indexPath.row < GamesList.count) {
self.gameState = GamesList[indexPath.row];
dispatch_async(dispatch_get_main_queue(), {}); //http://openradar.appspot.com/19563577
performSegueWithIdentifier("presentGame", sender: self);
} else {
let alert = UIAlertController(title: "Swipe!", message: "Swipe Invite To The Left", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: "OK!", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in }
alert.addAction(alertAction)
presentViewController(alert, animated: true) { () -> Void in }
}
}