
Question:
I am trying to figure out how to use a UINavigationController, UITabBarController, and UITableView together.
I started with a Navigation-based app, and at one point push a UIViewController (called CarViewController
) onto the navigationController. I want to use a TabBar within the CarViewController
, so I dragged a UITabBarController into CarViewController
's .xib, declared a IBOutlet UITabBarController *tabBarController
in the .h file, synthesized it in the .m file, then in Interface Builder I connected File's Owner -> tabBarController
to the tab bar controller and made File's Owner the tab bar's delegate.
This works just fine with tabs for other UIViews, but the problem I'm having is that I cannot get any tabs to work that have UITableViewControllers. The debugger claims there's an error in tableView:numberOfRowsInSection
but I have an NSLog in there that's not even being run.
Here's what the debugger output is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x592f1d0' *** Call stack at first throw: ( 0 CoreFoundation 0x0238e919 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x024dc5de objc_exception_throw + 47 2 CoreFoundation 0x0239042b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x02300116 ___forwarding___ + 966 4 CoreFoundation 0x022ffcd2 _CF_forwarding_prep_0 + 50 5 UIKit 0x001c9a24 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834 6 UIKit 0x001cb9c1 -[UITableViewRowData rectForFooterInSection:] + 108 7 UIKit 0x001cb24d -[UITableViewRowData heightForTable] + 60 8 UIKit 0x0008e596 -[UITableView(_UITableViewPrivate) _updateContentSize] + 333 9 UIKit 0x0007db7e -[UITableView noteNumberOfRowsChanged] + 123 10 UIKit 0x0008a1d2 -[UITableView reloadData] + 773 11 UIKit 0x000873f4 -[UITableView layoutSubviews] + 42 12 QuartzCore 0x03a630d5 -[CALayer layoutSublayers] + 177 13 QuartzCore 0x03a62e05 CALayerLayoutIfNeeded + 220 14 QuartzCore 0x03a6264c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 302 15 QuartzCore 0x03a622b0 _ZN2CA11Transaction6commitEv + 292 16 QuartzCore 0x03a69f5b _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 17 CoreFoundation 0x0236fd1b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 18 CoreFoundation 0x02304987 __CFRunLoopDoObservers + 295 19 CoreFoundation 0x022cdc17 __CFRunLoopRun + 1575 20 CoreFoundation 0x022cd280 CFRunLoopRunSpecific + 208 21 CoreFoundation 0x022cd1a1 CFRunLoopRunInMode + 97 22 GraphicsServices 0x025d92c8 GSEventRunModal + 217 23 GraphicsServices 0x025d938d GSEventRun + 115 24 UIKit 0x00022b58 UIApplicationMain + 1160 25 Test Application 0x000029b4 main + 102 26 Test Application 0x00002945 start + 53 27 ??? 0x00000001 0x0 + 1 ) terminate called after throwing an instance of 'NSException' sharedlibrary apply-load-rules all
Just for reference, here is the applicable code from the UITableViewController's implementation:
#pragma mark - #pragma mark Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSLog(@"Hi, this is the function that should be firing but is not!"); return 5; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell... cell.textLabel.text = @"Test Item"; return cell; }
At this point I have a blank project and I'm just trying to mock up the interface, so other than having this mis-structured there's nothing else going on in the code.
Solution:1
It appears to be calling the UITableViewDelegate methods on a UIViewController
. Re-check the connections in IB - occasionally even the best mis-wire things...
Solution:2
Well, for some reason, your program is trying to call tableView:numberOfRowsInSection: on an instance of UIViewController, and not UITableViewController :
[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x592f1d0'
I don't know why but that should be a good starting point for your investigations...
Solution:3
Check your TabBarController in IB. You have to change the type of view controller to table view controller or you will get this trace.(In the Tab Bar Controller Attribute).
Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
EmoticonEmoticon