I have a view hierarchy that has a UIViewController as Fi开发者_运维技巧les Owner in the XIB.
I need to add a UITableView into the hierarchy that has it's own controller (a UITableViewController subclass) because I am implementing a pull-to-refresh UI using http://github.com/leah/PullToRefresh
What I did:
- created the new UITableViewController subclass,
BuddyTableViewController
- implemented the datasource & delegate methods
- added the UITableView into the hierarchy in Interface Builder
- dropped an NSObject into the XIB and set the class to
BuddyTableViewController
- set the delegate & datasource of the tableview to
BuddyTableViewController
and hooked the UITableView to the tableView property ofBuddyTableViewController
When the view displays it crashes immediately.
When running in debug with NSZombieEnable=YES
reveals the message:
*** -[BuddyTableViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x69551d0
numberOfSectionsInTableView
only contains return 1;
I don't understand why BuddyTableViewController
is being deallocated.
You need to hook it up to an outlet in the owner, having it as delegate and data source is not enough because neither of those retains it. If the object is not retained by you it will be autoreleased.
精彩评论