performSegueWithIdentifier不总是在Swift中工作

performSegueWithIdentifier不总是在Swift中工作,swift,uitableview,segue,Swift,Uitableview,Segue,我有一个UITableView,上面有几个单元格,每当我按下其中一个单元格时,我想切换到另一个屏幕。我的代码工作正常,有点。。。。但有时我不得不推两次手机才能继续 有人知道为什么吗 func tableView(gamesListTableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if (indexPath.row < GamesList.count) { self.ga

我有一个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;
    }
}
func tableView(游戏列表视图:UITableView,didSelectRowAtIndexPath:nsindepath){
if(indexPath.rowVoid in}
alert.addAction(alertAction)
presentViewController(警报,动画:true){()->Void in}
}
}
重写func prepareforsgue(segue:UIStoryboardSegue,sender:AnyObject!){
如果(segue.identifier==“presentGame”){
var presentGame=segue.destinationViewController as!Game;
presentGame.gameState=self.gameState;
}
}

在野外存在一个已知的问题,即需要虚拟分派异步调用作为解决方法-可能在将来的版本中它会消失。以下是具有变通方法的代码的外观:

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 }
    }
}
func tableView(游戏列表视图:UITableView,didSelectRowAtIndexPath:nsindepath){
if(indexPath.rowVoid in}
alert.addAction(alertAction)
presentViewController(警报,动画:true){()->Void in}
}
}

你能告诉我如何在我的代码中使用该函数吗?对不起,我弄错了:)你的代码在swift中,我提供了objc代码片段。我会在一秒钟内为你的代码编辑我的帖子。谢谢你的编辑。但它无法编译,因为我必须添加一些self。与所使用的变量相关联。我最后用了这个来代替^Hm,闭包捕获了唯一的自引用,所以您需要周围的弱引用:-/好吧,看来你已经明白了:)很高兴我能帮上忙。