在两个不起作用的对象之间发送数据

时间:2016-04-15 16:21:34

标签: ios swift uinavigationcontroller uicollectionview

我目前正在尝试将数据从一个Viewcontroller中的UICollectionViewCell传递到另一个名为GameLobbyViewController的数据。

ViewController.swift

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let gameLobbyViewController: GameLobbyViewController = GameLobbyViewController()
        gameLobbyViewController.lobbyModelObject = lobbyGames[indexPath.row]
        self.navigationController?.pushViewController(gameLobbyViewController, animated: true)
    }

GameLobbyViewController

class GameLobbyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var lobbyModelObject: LobbyGameModel!

当我通过调试器时,当我停在这行代码时: gameLobbyViewController.lobbyModelObject = lobbyGames[indexPath.row] 它显示该值设置为此对象,但是当我单击该单元格时,它表示lobbyModelObject为nil。我做错了什么?

修改

我可以打印所传递的lobbyObjectModel的所有字段,但是当我将UILabel分配给lobbyModelObject的值时,fatal error: unexpectedly found nil while unwrapping an Optional value会被抛出。

0 个答案:

没有答案
相关问题