我正在将此代码用于表委托 当我滚动表到最后一行,即langTable时,我的应用程序崩溃了 如果有时应用程序没有崩溃,那么我无法滚动表
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Test 0");
if (tableView==langTable) {
NSLog(@"Test 0 complete lang table %d",[langArray count]);
return [langArray count];
}else if (tableView==gameTypeTable) {
NSLog(@"Test 0 complete gametype %d",[gameTypeArray count]);
return [gameTypeArray count];
}
NSLog(@"Test 0 complete 0");
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue;
if (tableView==langTable) {
NSLog(@"1Test 1...%d-%@",indexPath.row,[[langArray objectAtIndex:indexPath.row] objectForKey:@"lang_caption"]);
cellValue = [[langArray objectAtIndex:indexPath.row] objectForKey:@"lang_caption"];
}else if (tableView==gameTypeTable) {
NSLog(@"2Test 1...%d-%@",indexPath.row,[[gameTypeArray objectAtIndex:indexPath.row] objectForKey:@"caption"]);
cellValue = [[gameTypeArray objectAtIndex:indexPath.row] objectForKey:@"caption"];
}else {
NSLog(@"3Test 1...%d-kuch.ni.hai",indexPath.row);
cellValue = @"";
}
cell.text = cellValue;
NSLog(@"Text 1 Complete");
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"select");
if (tableView==langTable) {
NSLog(@"langTable1");
functionality.gameLang = indexPath.row;
NSLog(@"langTable2");
}else if (tableView==gameTypeTable) {
NSLog(@"gameTypeTable1");
functionality.gameType = indexPath.row;
NSLog(@"gameTypeTable2");
}
}
崩溃时间的日志是
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x026a7919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027f55de objc_exception_throw + 47
2 CoreFoundation 0x0269d465 -[__NSArrayM objectAtIndex:] + 261
3 SensoryStimulation 0x00006fe5 -[Functionality onPageChange:] + 829
4 SensoryStimulation 0x000029cc -[SensoryStimulationViewController scrollViewDidEndDecelerating:] + 126
5 UIKit 0x0030b0ad -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 322
6 UIKit 0x00315fbb -[UIScrollView(Static) _smoothScroll:] + 3999
7 UIKit 0x003337b8 -[UITableView(_UITableViewPrivate) _smoothScroll:] + 75
8 UIKit 0x00301e88 ScrollerHeartbeatCallback + 129
9 GraphicsServices 0x02e9556d HeartbeatTimerCallback + 35
10 CoreFoundation 0x02688d43 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
11 CoreFoundation 0x0268a384 __CFRunLoopDoTimer + 1364
12 CoreFoundation 0x025e6d09 __CFRunLoopRun + 1817
13 CoreFoundation 0x025e6280 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x025e61a1 CFRunLoopRunInMode + 97
15 GraphicsServices 0x02e922c8 GSEventRunModal + 217
16 GraphicsServices 0x02e9238d GSEventRun + 115
17 UIKit 0x002d5b58 UIApplicationMain + 1160
18 SensoryStimulation 0x000027aa main + 84
19 SensoryStimulation 0x0000272a start + 54
)
terminate called after throwing an instance of 'NSException'
代码错误
Amit Battan
答案 0 :(得分:0)
我发现了错误的事情 实际上我也在我的应用程序中使用UIScrollView,当表滚动结束然后滚动查看我用于UIScrollView的方法调用。 由于UITableView具有超类UIScrolView
Amit Battan