2015-06-13 49 views
0

在準備segue時嘗試在公共屬性中設置字符串時出現以下錯誤。任何想法爲什麼?在prepareForSegue中設置屬性時出錯:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setQuestionObjectId:]: unrecognized selector sent to instance 0x7fa713562b40' 

的代碼是:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([[segue identifier] isEqualToString:@"postSegue"]) { 
    CommentsViewControllerNew *commentsVC = (CommentsViewControllerNew *)[segue destinationViewController]; 
    commentsVC.hidesBottomBarWhenPushed = YES; 
    PFObject * question=[self.brightenArray objectAtIndex:self.indexPathOfClickedpost.row]; 
    commentsVC.questionObjectId=question.objectId; 
    NSLog(@"%@",[self.Array objectAtIndex:self.indexPathOfClickedpost.row]); 
//  commentsVC.question = question; 
+0

請顯示您的'CommentsViewControllerNew'代碼,以便我們可以看到您的@property的問題。 –

回答

0

正如你可能已經聚集,因爲你發送setQuestionObjectId:消息不承認該消息類,這是造成的。例如。如果您發送reloadData(從UITableView)消息到NSString,那麼您將收到類似的異常。這是因爲NSString沒有實現(有一個方法),稱爲reloadData

此錯誤經常發生在prepareForSegue:sender:方法中,因爲您將UIViewController轉換爲自定義子類(在本例中爲CommentsViewControllerNew)。該類型轉換髮生在這條線:

CommentsViewControllerNew *commentsVC = (CommentsViewControllerNew *)[segue destinationViewController]; 

你基本上是告訴編譯器:是的,我知道你會覺得這是一個UIViewController但它實際上是一個CommentsViewControllerNew。在危機來臨,因爲,在這種情況下,編譯器是正確的,它一個UIViewControllerUIViewController沒有叫questionObjectID

,長期經過解釋的方法或屬性名稱...修復的方法是去到Interface Builder中,選擇相關的視圖控制器並將其類設置爲CommentsViewControllerNew

注意:如果您不瞭解或不熟悉我正在談論的任何內容,我建議您閱讀或做一些教程。 YouTube上有很多好的。

相關問題