Extending a UIViewController with a different NIB file
Ok, I am definitely doing something wrong here...
I have create a BaseViewController that is the datasource and delegate of an matching NIB file containing a UITableView. This controller is responsible pretty much for getting data from a remote web service, creating the cells, and populating the UITableView.
So now I want to create a SearchViewController, so that I can get a UISearchBar that a user can enter a search query, post it on the web service, get the results and populate a UITableView.
However most of the code (in retrieving the data/populating the UITableView) exists in BaseViewController. So the firs开发者_如何学Pythont thing I thought of is to create the SearchViewController as an extension of BaseViewController with a different NIB file.
I've created the new NIB file called SearchView containing a UISearchBar and a UITableView and linked those two with the File Owners IBOutlets. (The UITableView IBOutlet is being inherited from BaseViewController)
So finally in my MainWindow.xib I've added a TabBarController and from the IB I've linked the UINavigationController to load the SearchViewController with View being loaded from SearchView. When I switch to the search tab, I am getting a SIG_ABORT with error:
-[UITableViewController loadView] loaded the "SearchView" nib but didn't get a UITableView
Could anyone point me in the right direction on how to proceed? I am sure most of you doing stuff with UITableView have reused code by extended a class. Is this the correct approach?
I'm not sure that I follow your description exactly, but what I think you should do is create your SearchViewController as a subclass of BaseViewController, like
@interface EventListViewController : UIViewController { ... }
Is that what you mean by "extending" BaseViewController?
And then you're using [[SearchViewController alloc] initWithNibName:@"SearchView" bundle:nil]
to create your SearchViewController? I usually handle the initial view loading of my apps programmatically in the app delegate.
The error you get sounds like your IBOutlet connections are wrong somehow. Too bad you can't post a nib file here as easily as you can post code.
精彩评论