UPDATE: I’ve solved this now – see my own comment. Amazing how often writing out the problem can lead to the resolution when you go through it again!
I must have read every thread on SO and the examples on Apple, but I just can’t get this to work in my case and I wonder what I’m doing wrong?
I have made a custom cell in IB with XCode 4. The file’s owner is set to the class of the custom view controller for the table and I have an IBOutlet for the UITableView cell which is hooked up OK from what I can tell. I normally do all my table cells via code and use the fast scrolling method, but for this project I really need to use nibs to load the cell content and I’m having some grief I can’t figure out.
So in my interface file I have;
@interface myCustomTableViewController <various delegates> {
UITableViewCell *customNibCell;
...
}
@property (nonatomic,assign) IBOutlet UITableViewCell *customNibCell;
In the customTableViewController I do this in my cellForRowAtIndexPath;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@:"customDirCell"];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DirectoryCellWithMenu" owner:self options: nil];
cell = customNibCell;
self.customNibCell = nil;
}
[self configureCell:cell atRow:indexPath.row];
And my configureCell method does this to reach into the cell and pull out the things I wish to customise.
UIImageView *fileImageView = (UIImageView *)[cell viewWithTag:3];
UILabel *headingTextLabel = (UILabel *)[cell viewWithTag:4];
UILabel *modifiedTextLabel = (UILabel *)[cell viewWithTag:5];
UILabel *sizeTextLabel = (UILabel *)[cell viewWithTag:6];
The Problem
The cells do load into the table OK in as much as I can see the correct layout. Furthermore, the custom actions I have defined on various buttons do all fire OK so it seems that the cell is hooked up properly.
BUT none of the customisation works – I can’t seem to change the text of any of the labels for example and on investigation, the result of every [cell viewWithTag:nn] is nil which clearly signposts the problem, but I can’t see what the cause is.
- The identifier for the
UITableViewCell is set to
“customDirCell” - The object identities for the labels
etc are indeed 3,4,5,6 according to
IB - The xib contains exactly 1 object,
the UITableViewCell
I can’t see anything wrong with either the nib file creation or the code, but I’m obviously missing something!
Can any kind soul shed light on where I should be looking?
I’ve resolved this as per my comment.