UITabBarController + UITableView =错误!
我想弄清楚如何一起使用UINavigationController,UITabBarController和UITableView。UITabBarController + UITableView =错误!
我开始使用基于导航的应用程序,并且一次将UIViewController(称为CarViewController
)推到navigationController上。我想在CarViewController
中使用TabBar,所以我将UITabBarController拖入CarViewController
的.xib文件中,在.h文件中声明为IBOutlet UITabBarController *tabBarController
,在.m文件中合成它,然后在Interface Builder中将File's Owner -> tabBarController
连接到标签栏控制器并使File's Owner成为选项卡的代表。
这适用于其他UIViews的标签,但我遇到的问题是,我无法获得任何标签工作,有UITableViewControllers。调试器声称在tableView:numberOfRowsInSection
中有错误,但我有一个NSLog,甚至没有运行。
这里的调试器输出是什么:
*** 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
仅供参考,这里是从的UITableViewController的实现应用代码:
#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;
}
在这一点上我有一个空白的项目和我m只是试图模拟界面,所以除了这个错误的结构之外,代码中没有其他的东西。
这似乎是呼吁一个UIViewController
中的UITableViewDelegate方法。重新检查IB中的连接 - 偶尔甚至是最好的线路错误...
那么,出于某种原因,你的程序试图调用的tableView:numberOfRowsInSection:在UIViewController的实例,而不是的UITableViewController:
[的UIViewController的tableView:numberOfRowsInSection:]:无法识别的选择发送到实例0x592f1d0 “
我不知道为什么,但应该是为你调查一个很好的起点......
检查IB中的TabBarController。您必须将视图控制器的类型更改为表视图控制器,否则您将获得此跟踪(在选项卡栏控制器属性中)。
就是这样! – 2010-08-10 15:55:28