ios - Error when setting property in prepareForSegue: -
i'm getting following error when trying set string in public property in prepare segue. idea why?
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[uiviewcontroller setquestionobjectid:]: unrecognized selector sent instance 0x7fa713562b40' the code is:
- (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;
as may have gathered, caused because sending setquestionobjectid: message class doesn't recognise message. e.g. if send reloaddata (from uitableview) message nsstring similar exception. because nsstring doesn't implement (have method) called reloaddata.
this error happens in prepareforsegue:sender: method because typecasting uiviewcontroller custom subclass (in case commentsviewcontrollernew). typecasting happens on line:
commentsviewcontrollernew *commentsvc = (commentsviewcontrollernew *)[segue destinationviewcontroller]; you telling compiler: yes know think uiviewcontroller it's commentsviewcontrollernew. crash comes because, in case compiler right, is uiviewcontroller , uiviewcontroller doesn't have method or property name called questionobjectid
after long explanation... fix go interface builder, select relevant view controller , set class commentsviewcontrollernew.
note: if don't understand, or unfamiliar of i'm talking about, suggest reading or few tutorials. there loads of ones on youtube.
Comments
Post a Comment