2015-06-13 48 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上有很多好的。

相关问题