1

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

enter image description here

enter image description here

Thank you very much.

  • 1
    You don't believe the message?? "cell" is definitely a UITableViewCell. – Hot Licks Oct 12 '13 at 22:48
  • @HotLicks I'm sorry, I don't understand your comment. The statement `ITCourseDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];` means that `cell` is a `ITCourseDetailTableViewCell` which is a subclass of `UITableViewCell`. The only way I was able to fix this was to delete the class and recreate another one using the exact same code. –  Oct 12 '13 at 22:57
  • I mean the message meant that the item being "sent" setLecture was a UITableViewCell. This is clear and as positive and truthful a statement as one can make about anything computer. It is unclear why that class and not your subclass ended up in "cell", but that's the problem one should debug, not wonder why the error message was "wrong". – Hot Licks Oct 13 '13 at 02:31
  • @HotLicks absolutely agree! –  Oct 13 '13 at 02:33
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:50

2 Answers2

1

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!

in IB

  • select your cell view,
  • open the inspector and goto to tab 3.
  • Fill out 'Custom Class' to point to YOUR class
Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Thank you for the answer. I did not know what. I changed it, but am running into the same issue `*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setLecture:]: unrecognized selector sent to instance 0x8947930'` –  Oct 12 '13 at 20:36
  • Thanks again. I've added screenshots, I think I've set it up correctly. When I type "cell" it shows that its an instance of `ITCourseDetailTableViewCell`. But I do see your point. I tried to clean the build folder, but that did not help. –  Oct 12 '13 at 20:49
0

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))
Emmanuel
  • 323
  • 2
  • 3