Reputation:
I've tried to go through the other questions regarding the same issue, but could not figure out an answer.
Error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setLecture:]: unrecognized selector sent to instance 0xa85d800'
Here are relevant snippets from the code:
// UITableViewCell .h
@interface ITCourseDetailTableViewCell : UITableViewCell
@property (strong, nonatomic) ITClass * lecture;
@property (strong, nonatomic) IBOutlet UILabel *lectureCode;
- (void)setLecture:(ITClass *)lecture;
@end
// UITableViewCell .m
- (void)setLecture:(ITClass *)lecture
{
self.lecture = lecture;
self.lectureCode.text = self.lecture.classCode;
}
Here is method being called. Also, this is where the issue is happening:
// view controller .m
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentifier = @"ITCourseDetailTableViewCell";
ITCourseDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
NSArray * nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
ITClass * currentClass = [[[self course] courseLectures] objectAtIndex:indexPath.row];
cell.lecture = currentClass;
return cell;
}
Issue happens on this call: cell.lecture = currentClass;
The method definitely exists in the cell class. In the stack trace I can confirm that the correct cell is being instantiated and it has a _lecture
instance variable.
Relevant screenshots to confirm that the class is correctly set in the IB
Thank you very much.
Upvotes: 1
Views: 3284
Reputation: 343
Had the same problem with unrecognized selector. I added self to the selector function as below and it worked.
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTapOnDescription))
Upvotes: 0
Reputation: 50089
you aren't using your subclass of the table cell. The error shows you try to use regular UITableCell instances. Make sure you set the cell class in the nib you use for the cell in IB!
Upvotes: 1