Why is my Interface Builder wiring so bonkers and what can I do to straighten it out?
Posted
by editor
on Stack Overflow
See other posts from Stack Overflow
or by editor
Published on 2010-05-02T22:53:13Z
Indexed on
2010/05/02
22:57 UTC
Read the original article
Hit count: 304
I've been working on an iPhone application in XCode and Interface Builder of the Tab Bar project type. After getting a table view of topics (business sectors) working fine I realized that I would need to add a Navigation Control to allow the user to drill into a subtopics (subsectors) table.
As a green Objective-C developer, that was confusing, but I managed to get it working by reading various documentation trying out a few different IB options. My current setup is a Tab Bar Controller with Tab 1 as a Navigation Controller and Tab 2 a plain view with a Table View placed into it. The wiring works: I can log when table rows are selected and I'm ready to push a new View Controller onto the stack so that I can display the subtopics Table View.
My problem: For some reason the first tab's Table View is a delegate and dataSource of the second ta. It doesn't make sense to me and I can't figure out why that's the only setup that works.
Here is the wiring:
- Navigation Controller (Sectors) is a
delegate of Tab Bar
- Navigation Bar is a delegate of Navigation Controller (Sectors)
- View Contoller (Sectors) has a view of Table View
- Table View (in Navigation Controller (Sectors)) is a delegate of First View Controller (Companies)
- Table View (in Navigation Controller (Sectors)) is a dataSource outlet of First View Controller (Companies)
- First View Controller (Companies)
- First View Contoller (Sectors) has a view of Table View
- Table View (in First View Controller (Companies)) is not hooked up to a dataSource outlet and is not a delegate
When I click the tab buttons and look at the Inspector I see that the first tab is correctly hooked up to my MainWindow.xib and the second tab has selected a nib called SecondView.xib. It's in the File's Owner of MainWindow.xib where I inherit UITableViewDataSource and UITableViewDelegate (and also UITabBarControllerDelegate) in the .h, and in the .m where I implement the delegate methods.
Why does this setup only work when the Table View in my first tab (View Controller (Sectors)) is a delegate and dataSource of the second tab? I'm confused: why wouldn't it need to be hooked up to the Navigation Controller-enabled tab in which the Table View is seen (Navigation Controller (Sectors))? The Table View seen on the second tab has neither dataSource and is not a delegate.
I'm having trouble getting a pushViewController to fire (self.navigationController is not nil but the new View Controller still doesn't load) and I suspect that I need to work out this IB wiring issue before I can troubleshoot why the Nav Controller won't push a new View Controller onto the stack.
if(nil == self.navigationController) {
NSLog(@"self.navigationController is nil.");
} else {
NSLog(@"self.navigationController is not nil.");
SectorList *subsectorViewController = [[SectorList alloc] initWithNibName:@"SectorList" bundle:nil];
subsectorViewController.title = @"Subsectors";
[[self navigationController] pushViewController:subsectorViewController animated:YES];
[subsectorViewController release];
}
© Stack Overflow or respective owner