在prepareForSegue中传递Dictionary时,应用程序崩溃

时间:2014-11-18 16:46:43

标签: ios dictionary swift nsdictionary segue

所以,我已经完成了这一百万次,但今天,似乎我的大脑已经停止了,而且我完全坚持了这个......这就是:

我必须通过Push Segue将JSON responseDict传递给CollectionViewController。回复是来自Instagram的时间表。

在我的sourceVC中,Dictionary的定义如下:var timelineResponse: [String : AnyObject]?并且在我的destinationVC中,响应词典的定义方式与var responseDict: [String : AnyObject]?相同{尽管我已尝试将其定义为各种方式看看那是不是问题。

   override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if let identifier = segue.identifier {
            if (identifier == "photoSegue") {

                //This println correctly outputs the contents of the dict, so I know that the dict is not nil before passing it.
                println("sending timelineResponseDict to PhotoCollView with following data: \(timelineResponse)")

                  // I've tried the following two methods of passing the dict to my PhotoCollView
//                (segue.destinationViewController as PhotoCollectionView).responseDict = timelineResponse!

                let toVC: PhotoCollectionView = segue.destinationViewController as PhotoCollectionView
                toVC.responseDict = timelineResponse!
                toVC.stringResp = "Test"
            }
        }
    }

正如你所看到的,我试图传递一个测试字符串,看看它是否有效,它做了什么。所以它似乎是它不想传递的字典类型。但为什么呢?

解决

我试图将类型AnyObject传递给字典,因此崩溃了。很抱歉在这里浪费了一点时间! :/我感谢评论家伙们!

0 个答案:

没有答案