我想弄清楚如何一起使用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只是試圖模擬界面,所以除了這個錯誤的結構之外,代碼中沒有其他的東西。
就是這樣! – 2010-08-10 15:55:28