繁体   English   中英

滚动UITableView时iPhone应用程序崩溃

[英]Iphone application crashes when I scroll the UITableView

我正在使用此代码进行表委托,当我滚动表到最后一行时,我的应用程序崩溃了,即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)

我发现了错误的事情实际上,我还在我的应用程序中使用了UIScrollView,当表滚动结束时,然后使用了UIScrollView的scrollViewDidEndDecelerating方法调用。 由于UITableView具有超类UIScrolView

阿米特·巴坦(Amit Battan)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM