1
votes

I'm trying to create custom UIViewController with a UITableView, load the UIViewController using a xib file and add the view as a subview to another UIView.

The hierarchy is like this:

  • UIViewController
    • UIView << add custom UIViewController's view
    • UIView
    • UIView

Here's my xib view hierarchy and settings:

  • UIView
    • UITableView

Connection in IB:

  • File's Owner:CustomTableViewController
  • Outlets:
    • view connected to UIView
    • tableView connected to File's Owner
    • delegate connected to File's Owner
    • datasource connected to File's Owner

I have both UITableDataSource and UITableDelegate implemented. When i tried to add the view as a subview, it crashed ...

  - (void)viewDidLoad
  {
      [super viewDidLoad];
      CustomTableViewController* controller = [[CustomTableViewController alloc] initWithNibName:@"CustomTableView" bundle:[NSBundle mainBundle]];      
      [self.viewContainer addSubview:controller.view];   
  }

What am i missing?

1
Tell us more about the crash.Peter DeWeese
It stops in main() with this message: Thread 1: Program received signal: "EXC_BAD_ACCESS". ThanksEric
Sounds like something isn't retained that should be. Set an exception breakpoint and turn on zombies to help look for it. developer.apple.com/library/mac/ipad/#documentation/…Peter DeWeese
You're absolutely correct. I don't have instance variable that holds CustomTableViewController and that's why I'm getting the exception. I added a property and init with 'self.controller = [[CustomTableViewController alloc] initWithNibName:@"CustomTableView" bundle:[NSBundle mainBundle]];' That fix the problem. Thanks again Peter.Eric
Np. I added it as an answer so we can wrap this question up.Peter DeWeese

1 Answers

1
votes

Sounds Like something is not retained that should be. Set up an exception breakpoint and turn on zombies to find it. See askers results above.