UITableView滚动时应用程序崩溃

时间:2011-06-24 09:59:37

标签: iphone objective-c xcode ios4

我想知道当我滚动UITableView时我的应用程序崩溃的原因。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    NSArray *arrayForNames=[[NSArray alloc]initWithArray:[objContentManager getDuasNamesByGroupName:[arrayDuaGroups objectAtIndex:indexPath.section]]]; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
// implementation on cell    
}

当我在UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

向上滚动程序崩溃时

我看到了教程,所有我找不到任何不同的实现,它向下滚动相当平滑但当我向后滚动时它会立即崩溃,我不知道哪里出错了

> 2011-06-24 15:07:10.976
> Tasbeeh[503:207] *** Terminating app
> due to uncaught exception
> 'NSRangeException', reason: '***
> -[NSArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
> *** Call stack at first throw: (  0   CoreFoundation                     
> 0x02553919 __exceptionPreprocess + 185
>   1   libobjc.A.dylib                  
> 0x023685de objc_exception_throw + 47
>   2   CoreFoundation                   
> 0x0254958c -[__NSArrayI
> objectAtIndex:] + 236     3   Tasbeeh    
> 0x00002922 -[ClassDuaTableCategory
> tableView:cellForRowAtIndexPath:] +
> 553   4   UIKit                        
> 0x00326a3f
> -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
> + 619     5   UIKit                               0x0031cad2
> -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75     6   UIKit                            
> 0x00331337
> -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1348    7   UIKit                              
> 0x003294bc -[UITableView
> layoutSubviews] + 242     8   QuartzCore 
> 0x040e30d5 -[CALayer layoutSublayers]
> + 177     9   QuartzCore                          0x040e2e05 CALayerLayoutIfNeeded + 220
>   10  QuartzCore                       
> 0x040e264c
> _ZN2CA7Context18commit_transactionEPNS_11TransactionE
> + 302     11  QuartzCore                          0x040e22b0
> _ZN2CA11Transaction6commitEv + 292    12  QuartzCore                         
> 0x040e9f5b
> _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv
> + 99  13  CoreFoundation                      0x02534d1b
> __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
> + 27  14  CoreFoundation                      0x024c9987 __CFRunLoopDoObservers +
> 295   15  CoreFoundation               
> 0x02492c17 __CFRunLoopRun + 1575  16 
> CoreFoundation                     
> 0x02492280 CFRunLoopRunSpecific + 208
>   17  CoreFoundation                   
> 0x024921a1 CFRunLoopRunInMode + 97    18
> GraphicsServices                   
> 0x02cb82c8 GSEventRunModal + 217  19 
> GraphicsServices                   
> 0x02cb838d GSEventRun + 115   20  UIKit
> 0x002c4b58 UIApplicationMain + 1160
>   21  Tasbeeh                          
> 0x00002024 main + 102     22  Tasbeeh    
> 0x00001fb5 start + 53 ) terminate
> called after throwing an instance of
> 'NSException' Program received signal:
> “SIGABRT”.

请建议我。

谢谢。

5 个答案:

答案 0 :(得分:3)

请检查tableview控制器的nib文件。

应该有一个"表格视图"在你的视图控制器下。

单击以查看表视图的属性检查器。

检查"内容"看它是否被分配"动态原型"或"静态单元"?

更改"静态单元"动态原型"动态原型"或许可以解决你的问题。

答案 1 :(得分:1)

indexPath是否可能转到指向数组arrayDuaGroups的无效索引的值 ?

答案 2 :(得分:1)

尝试评论cell = nil如果并且只让cell = part,如果它是我认为它将修复它

 // if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//    }

编辑: 查看日志后 - 问题是数组作为数据源,当它试图重建它在数组中没有找到任何内容的单元格(arrayDuaGroups)时,它是空的,在类接口中使用retain属性声明你的数组并检查是否arrayDuaGroups为空

答案 3 :(得分:0)

尝试使用以下

NSString *CellIdentifier = [NSString stringWithFormat:@"Cell_%d_%d",indexPath.section,indexPath.row];

EDITED:

您遇到了NSArray的问题,您正试图访问数组中不存在的元素,

您的arrayDuaGroups数组在索引indexPath.section没有任何对象。

在获取对象之前检查arrayDuaGroups数组内容和长度。

[arrayDuaGroups objectAtIndex:indexPath.section]

答案 4 :(得分:0)

似乎数组超出范围异常。您的阵列是问题所在。你不应该将数组分配到cellForRowAtIndexPath方法中。在viewDidLoad方法中填充数据,然后使用该数组在单元格中显示数据。

相关问题