UITableViewCell From Nib
As far as I can tell, this is the best and most correct way to create a custom UITableViewCell that has a backing Objective-C class (so custom subviews) and is layed out using a Nib. If anyone knows of a better way to do it, let me know. There’s a bunch of conflicting information on the web.
- Create your Nib
- Remove the default UIView from XIB, replace it with a UITableViewCell
- Update: Remember to set a reuse identifier in the NIB properties. It cannot be set programmatically.
- Create your UITableViewCell subclass in Objective-C
- Set the class of the cell in IB to be your custom class
- Manually write your UIOutlet properties for the custom view properties you want to access from the cell.
- Add sub-views in IB that correspond to those outlets
- Select the cell and open the right menu, right tab (Connections inspector). There you should see the custom outlets you just coded up in the Outlets list
- Select the handle to the right of each outlet and drag it over to the subview in IB that corresponds to that outlet
- Finally, in your
tableView:cellForRowAtIndexPath:
method, instantiate the cell
The cell needs to be instantiated using the Nib to display your custom layout:
1 2 3 4 5 6 7 8 9 10 |
|