I have an application that was not originally a storyboard application. I've since added a storyboard for a feature branch, and there is a subclass of UITableViewController
on it. I've created a prototype cell with several UILabels
and UIImageViews
, and added tags for each of them. The prototype cell has the correct identifier.
I've registered the class with the identifier:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CustomCell"];
When I try to dequeue the custom cell and access its views:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath];
UIImageView *icon = (UIImageView *)[cell viewWithTag:1];
The view (icon) is nil.
I've also tried subclassing it, and registering the subclass with the reuse identifier, and setting the UITableViewCell
with the subclass name in the prototype. In that case,
UIImageView *icon = cell.icon;
still returns nil.
Is there something to do with the storyboard not being the main one? I've had other projects where prototype cells with custom subviews
just works fine without all of this trouble. Is there a way to register the custom class or UITableViewCell
with custom identifier, but specify which storyboard it's from?
[cell.contentView viewWithTag:1]
? – andrewbuilder