Swift - prepareForSegue返回nil

时间:2015-02-04 16:22:30

标签: swift uiviewcontroller segue

我是 iOS Swift 的新手,非常感谢。

我想通过tripListDataaddNewWishViewController传递给第二个 ViewController prepareForSegue):

var tripListData: NSMutableArray = NSMutableArray()
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "goToAddNewWishVC" {
        var selectedIndexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
        var addNewWishViewController: AddNewWishViewController = segue.destinationViewController as AddNewWishViewController

        addNewWishViewController.tripDataFromTripList = tripListData.objectAtIndex(selectedIndexPath.row) as? NSDictionary

        println(tripListData.objectAtIndex(selectedIndexPath.row))
        println(addNewWishViewController.tripDataFromTripList)
    }
}

没有错误,但第二个println始终返回nil。因此,它在第二个 ViewController 中崩溃,因为tripDataFRomTripListnil。以下是println结果:

<Destination: 0x7f9401cd84f0, objectId: nCK0VvwueZ, localId: (null)> {
dateAdd = "29/01/2015";
dateFly = "28/02/2015";
destinationCity = Frankfurt;
sourceCity = Hong Kong;
user = "<PFUser: 0x7f9401dc6d00, objectId: 71cgaaZcvw>";
}
nil

这是addNewWishViewController

class AddNewWishViewController: UIViewController {
@IBOutlet var newWishList: UITextView! = UITextView()
@IBOutlet var tripInfoTextField: UILabel!

var tripDataFromTripList:NSDictionary? = NSDictionary()

override func viewDidLoad() {
    super.viewDidLoad()

    if tripDataFromTripList == nil{
        println("nodata")
    }else{
         println(tripDataFromTripList!)   
    }

出现这种情况的原因是什么? 再次感谢:)

0 个答案:

没有答案