Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between custom cell class vs files owner

Tags:

ios

In the official developer guide(and other guides like it), it mentions that you need to set the custom class property of a cell in order to make IBOutlet connections. This custom class is simply an objective c class with IBOutlet markers on @properties. What I'm struggling to understand is how this custom class property for a cell differs from files owner of a XIB. From my experimentation, I can leave files owner blank and all of the connections still work as long as the custom class is set on the cell(I click on the cell and go to "identity inspector" and set the custom class of the cell). I thought that a files owner is the only thing the UI views can interact with.

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html

ctrl+f "To use outlets for the custom cell content" to get to the spot in the docs.

like image 430
user1099123 Avatar asked Feb 17 '23 00:02

user1099123


1 Answers

I had the same question and experimented around a bit. From what I can see, the Custom Class attribute is applicable for every view in your XIB. Ie if you have a XIB with a UI design that has several UI objects, each can have a separate custom class. The custom class, must also be a subclass of the parent class of the UIView object you have in you XIB. For example for a cell the custom class must be a UITableViewCell.

The File Owner on the other hand is only one and for the entire XIB. It can be ANY class (from what I can see). In my case as an example, I have XIB with custom UITableViewCell with a text field and some labels. I use the cell as the Header View of a table (i.e. in a UITableView object).

In my case I did NOT create a custom class for my XIB. I just made the cell's file owner my UITableViewController (which is manage my tableview), and connected my textfield and labels to properties in the UITableViewController class. This works for me as I only ever have ONE instance my custom TableViewCell (its the header of the entire table, and there is only one header).

like image 183
iansari Avatar answered Mar 15 '23 23:03

iansari