1

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?

5
  • Tell us more about the crash. Commented Jan 3, 2012 at 2:02
  • It stops in main() with this message: Thread 1: Program received signal: "EXC_BAD_ACCESS". Thanks Commented Jan 3, 2012 at 2:39
  • 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/… Commented Jan 3, 2012 at 3:56
  • 1
    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. Commented Jan 3, 2012 at 4:22
  • Np. I added it as an answer so we can wrap this question up. Commented Jan 3, 2012 at 4:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.