Search code examples
objective-ciosuitableviewuistoryboardiboutlet

Why can't I define IBOutlets when using custom "prototype tableviewcells"


I have my own table view cell which is defined in my storyboard. I have also defined a custom UITableViewCell class for this special cell. So when I want to create an Outlet for my custom prototype cell I get an error that the Outlet cant be created.

Since this is not possible I have to do some ugly workarounds and use the tags in IB to reference the individual labels and buttons later on in my code.

I don't really see why this is not possible and I wonder if working with tags and [myCell viewWithTag:] is the best possible way to go here?


Solution

  • Because the outlet is a one-to-one connection between your controller and a specific item within the view. In the case of a prototype cell, it is simply a description of a cell that can have an arbitrary number of different items (i.e. rows in your table view). How would the controller know which item you are referring to (e.g. row 5 or 500)? That is why you are receiving the error message.

    Lucas provided one method to refer to your connection via tags which works perfectly well.