私は以下のクラスを持っています。それは私が私のfriend?[indexPath.row]
をすることが確認されていてもエラーに
セグメンテーションされたコントローラにデータを渡す準備ができていません
fatal error: unexpectedly found nil while unwrapping an Optional value
を取得していますということですなぜ私は
var friends: [User]?
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("viewFriend", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destinationVC = segue.destinationViewController
if let friendsProfileVC = destinationVC as? FriendsProfileViewController{
if let indexPath = sender as? NSIndexPath{
print(indexPath.row)
friendsProfileVC.user = friends?[indexPath.row]
}
}
}
データを渡すために、次のでしたsegueingクラスで
class FriendsProfileViewController: UIViewController {
var user : User!
override func viewDidLoad() {
super.viewDidLoad()
print(user.firstName)
}
}
私がセグをするときに値を含んでいますか?
デバッグしましたか?はいの場合、何が起こっていますか? –
あなたは与えられたコードからのクラッシュに直面していますか?あなたは初期化されているか、それとも空ですか? –
'print(indexPath.row)'行のコンソール出力を取得していますか? –