2015-06-19 62 views
0

所以我在这个类中有2个函数,我正在研究需要使用相同的变量。该变量由SwiftyJSON框架中的JSON对象填充。在Swift中将值从1函数传递给另一个

我开始instaniating变量,像这样的:

var fooGame : JSON?; 

然后我填这个坏小子像这样:

func tableView(gamesListTableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    if (indexPath.row < InvitesList.count) { 
     //acceptInvite 
    } else { 
     performSegueWithIdentifier("presentGame", sender: self) 
     self.fooGame = GamesList[indexPath.row - InvitesList.count]; 

     println(self.fooGame); 
    } 
} 

这完美的作品和fooGame的价值被打印到控制台! 然而这是哪里出现问题,我想在这里再次使用self.fooGame值:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 
    if (segue.identifier == "presentGame") { 
     var svc = segue.destinationViewController as! Game; 

     println(self.fooGame); 
    } 
} 

在这里,我得到无印在控制台中。

+1

插入数据fooGame对象之前,您呼叫performSegueIdentifier后。 –

回答

3

更改的行顺序这两条线,因为你设置你fooGame执行赛格瑞

self.fooGame = GamesList[indexPath.row - InvitesList.count]; 
performSegueWithIdentifier("presentGame", sender: self) 
相关问题