views:

22

answers:

1

I have a view hierarchy that has a UIViewController as Files 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:

  1. created the new UITableViewController subclass, BuddyTableViewController
  2. implemented the datasource & delegate methods
  3. added the UITableView into the hierarchy in Interface Builder
  4. dropped an NSObject into the XIB and set the class to BuddyTableViewController
  5. set the delegate & datasource of the tableview to BuddyTableViewController and hooked the UITableView to the tableView property of BuddyTableViewController

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.

+1  A: 

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.

Aleph
evil tabby cat