Normally you don't have to bother about the File's owner in that case, because when the tableView
instantiates the cell from the provided/associated UINib
along with the reuseIdentifier
. It will load all the top-level objects of the nib, and use only the first top-level object that is of class UITableViewCell
(or maybe just the first top-level-object regardless of the class? but in general you only have your UITableViewCell
in your XIB anyway — without counting the File's Owner
and the First Responder
which are only "proxies").
In fact, the tableView
will try to dequeue a cell and if it doesn't find a reusable one, it will create a new one using the UINib
you provided. It will be something similar to this:
NSArray* topLevelObjects = [self.cellNib instantiateWithOwner:nil options:0];
cell = [topLevelObjects objectAtIndex:0];
(That's of course a simplified version just to show the idea, I don't know if it actually calls these exact lines, but it should be quite close)
So the File's Owner
is not used in this particular case, and you only need to put a simple custom UITableViewCell
as the only top-level-object of your XIB file next to the existing File's Owner
anf First Responder
(that, again, are only "proxies" / "External Objects references" and won't be instantiated and won't be part of the top-level-objects returned by instantiateWithOwner:options:
).
If it still doesn't work:
- Ensure that you correctly filled the
reuseIdentifier
of your UITableViewCell
in IB (in the Object Inspector pane on the right once you selected your cell in IB), and used the exact same value for this reuseIdentifier
property in IB that the one you use in your code.
- If still no luck, please provide more info, especially what kind of error, log message or exception you have.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…