In my table view’s cellForRowAtIndexPath I have
MenuItemCell *cell = (MenuItemCell *)[[[NSBundle mainBundle] loadNibNamed:@"ResultCell" owner:nil options:nil] objectAtIndex:0];
Before you tell me not to use a xib: I have more than one table view whose cells need to look identical. Using a xib seemed to be the best way to accomplish this.
The ResultCell xib in question is “owned” by MenuItemCell. MenuItemCell is a subclass of another subclass of UITableViewCell.
Here’s the problem: I put a breakpoint directly after the cell allocation line, and here are my lldb results:
(lldb) po [cell class]
(id) $3 = 0x00b6b5fc UITableViewCell
Why is my cell a UITableViewCell and not a MenuItemCell? (Or maybe it is and po isn’t the correct way to figure that out?)
You might not have told Xcode/Interface Builder to instantiate a MenuItemCell from the XIB, so it uses the default implementation, which is UITableViewCell. Note that casting an object only makes the compiler believe that it’s an instance of the specified class; it does not magically transform the object into an instance of the class. (In other words, it’s a copmile-time expression, not a runtime one.)