나는 UINavigationController, UITabBarController 및 UITableView를 함께 사용하는 방법을 알아 내려고하고있다.UITabBarController + UITableView = 오류!
네비게이션 기반 앱으로 시작하여 한 시점에서 navigationController에 UIViewController (CarViewController
)를 푸시합니다. CarViewController
내에서 TabBar를 사용하기 때문에 UITabBarController를 CarViewController
의 .xib로 드래그하고 .h 파일에 IBOutlet UITabBarController *tabBarController
을 선언하고 .m 파일에서 합성 한 다음 인터페이스 작성기에서 탭 막대에 File's Owner -> tabBarController
을 연결했습니다. 컨트롤러를 만들고 File 's Owner를 탭 바의 델리게이트로 만들었습니다.
다른 UIViews 탭으로 잘 작동하지만 내가 가지고있는 문제는 UITableViewControllers있는 작동하도록 모든 탭을 가져올 수 없다는 것입니다. 디버거는 tableView:numberOfRowsInSection
에 오류가 있다고 주장하지만 거기에는 실행중인 NSLog가 있습니다. 여기
#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;
}
이 시점에서 :
그냥 참조를 위해, 여기에있는 UITableViewController의 구현에서 해당 코드*** 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
인터페이스를 조롱하는 것 뿐이므로 잘못 구성된 것 외에는 코드에서 아무 일도 일어나지 않습니다. 의 UIViewController의 인스턴스에, 그리고있는 UITableViewController : numberOfRowsInSection를 :
예! –