Ios 配置静态UITableView节中的单元格数

Ios 配置静态UITableView节中的单元格数,ios,objective-c,uitableview,sigabrt,Ios,Objective C,Uitableview,Sigabrt,我有一个包含7个部分的静态表视图,但我希望第1部分是原型,所以我这样做是为了配置行: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 1) { return 1; } else { return [super tableView:tableView numberOfRowsInSecti

我有一个包含7个部分的静态表视图,但我希望第1部分是原型,所以我这样做是为了配置行:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 1) {
        return 1;
    } else {
        return [super tableView:tableView numberOfRowsInSection:section];
    }
}
但一切都很顺利,直到这一部分:

return 1;
程序在这一行之后崩溃。有没有一种方法可以解决这个问题,或者有一种解决方法也可以实现这一点。谢谢

注意:这是调用堆栈:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000105f6cf45 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x00000001059e6deb objc_exception_throw + 48
2   CoreFoundation                      0x0000000105f1b975 -[__NSArray0 objectAtIndex:] + 101
3   UIKit                               0x0000000106a263e8 -[UITableViewDataSource tableView:heightForRowAtIndexPath:] + 181
4   UIKit                               0x00000001066f622a -[UITableViewController tableView:heightForRowAtIndexPath:] + 63
5   UIKit                               0x000000010666b5cf __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 240
6   UIKit                               0x000000010666ac5f -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 4876
7   UIKit                               0x000000010666d2a7 -[UITableViewRowData _ensureSectionOffsetIsValidForSection:] + 279
8   UIKit                               0x00000001066708bb -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 423
9   UIKit                               0x00000001066709e8 -[UITableViewRowData heightForTable] + 62
10  UIKit                               0x000000010643c6a2 -[UITableView _updateContentSize] + 374
11  UIKit                               0x0000000106462f19 -[UITableView _rebuildGeometry] + 40
12  UIKit                               0x000000010646124e -[UITableView setLayoutMargins:] + 389
13  UIKit                               0x0000000106461090 -[UITableView _setDefaultLayoutMargins:] + 134
14  UIKit                               0x00000001064a2420 -[UIViewController _setContentOverlayInsets:] + 692
15  UIKit                               0x00000001064a2e43 -[UIViewController _updateContentOverlayInsetsFromParentIfNecessary] + 2067
16  UIKit                               0x00000001064a249d -[UIViewController _updateContentOverlayInsetsForSelfAndChildren] + 101
17  UIKit                               0x00000001064ae199 -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 972
18  UIKit                               0x00000001064b3c0b -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 1242
19  UIKit                               0x00000001063c7b45 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1613
20  UIKit                               0x00000001063dc5ba -[UIScrollView _didMoveFromWindow:toWindow:] + 85
21  UIKit                               0x00000001063c7856 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 862
22  UIKit                               0x00000001063bce2c __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 155
23  UIKit                               0x00000001063bcd2b -[UIView(Hierarchy) _postMovedFromSuperview:] + 544
24  UIKit                               0x00000001063ca7e7 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1967
25  UIKit                               0x000000010678b0ad -[UINavigationTransitionView transition:fromView:toView:] + 672
26  UIKit                               0x00000001064f1791 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3291
27  UIKit                               0x00000001064f1d8d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
28  UIKit                               0x00000001064f2cea -[UINavigationController __viewWillLayoutSubviews] + 57
29  UIKit                               0x0000000106698c85 -[UILayoutContainerView layoutSubviews] + 248
30  UIKit                               0x00000001063cde40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
31  QuartzCore                          0x0000000109e7b59a -[CALayer layoutSublayers] + 146
32  QuartzCore                          0x0000000109e6fe70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
33  QuartzCore                          0x0000000109e6fcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
34  QuartzCore                          0x0000000109e64475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
35  QuartzCore                          0x0000000109e91c0a _ZN2CA11Transaction6commitEv + 486
36  UIKit                               0x0000000106344216 _afterCACommitHandler + 174
37  CoreFoundation                      0x0000000105e98947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
38  CoreFoundation                      0x0000000105e988b7 __CFRunLoopDoObservers + 391
39  CoreFoundation                      0x0000000105e8e50b __CFRunLoopRun + 1147
40  CoreFoundation                      0x0000000105e8de08 CFRunLoopRunSpecific + 488
41  GraphicsServices                    0x0000000109708ad2 GSEventRunModal + 161
42  UIKit                               0x000000010631930d UIApplicationMain + 171
43  SilverStoryClient                   0x00000001054b325f main + 111
44  libdyld.dylib                       0x000000010869092d start + 1
45  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

堆栈跟踪显示您正在访问空数组的索引0

您应该检查数组是否正确填充

或者使用
guard
关键字(或其他if-else条件)来避免索引越界问题


Swift语言参考:。

出现了这个问题,我找到了确切的解决方案:

问题在于序列图像板属性检查器中的单元标识符名称和“let cellIdentifier=“cell”的单元标识符名称,如果这些名称不同,则肯定会导致sigabrt错误

因此,如果任何人有类似的问题,请使用此解决方案进行纠正

2015-12-01 11:31:26.301位置[2621:83370]*在[UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableView.m:6547中断言失败 2015-12-01 11:31:26.838该地点[2621:83370]*由于未捕获的异常“NSinternalinconsistenceexception”终止应用程序,原因:

'无法将具有标识符单元格的单元格出列

必须为标识符注册nib或类,或连接情节提要中的原型单元

First throw call stack:
(
    0   CoreFoundation                      0x000000010f74cf45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000111470deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010f74cdaa +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010fb955ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   UIKit                               0x00000001100ac615 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 275
    5   The Place                           0x000000010f56deb4 _TFC9The_Place14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 164
    6   The Place                           0x000000010f56e07f _TToFC9The_Place14ViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
    7   UIKit                               0x00000001100bee2a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
    8   UIKit                               0x00000001100bef3f -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    9   UIKit                               0x0000000110094307 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3187
    10  UIKit                               0x00000001100c7d1c -[UITableView _performWithCachedTraitCollection:] + 92
    11  UIKit                               0x00000001100af884 -[UITableView layoutSubviews] + 223
    12  UIKit                               0x000000011001de40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    13  QuartzCore                          0x00000001144b359a -[CALayer layoutSublayers] + 146
    14  QuartzCore                          0x00000001144a7e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    15  QuartzCore                          0x00000001144a7cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    16  QuartzCore                          0x000000011449c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    17  QuartzCore                          0x00000001144c9c0a _ZN2CA11Transaction6commitEv + 486
    18  QuartzCore                          0x00000001144ca37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    19  CoreFoundation                      0x000000010f678947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    20  CoreFoundation                      0x000000010f6788b7 __CFRunLoopDoObservers + 391
    21  CoreFoundation                      0x000000010f66de2c CFRunLoopRunSpecific + 524
    22  UIKit                               0x000000010ff644f5 -[UIApplication _run] + 402
    23  UIKit                               0x000000010ff6930d UIApplicationMain + 171
    24  The Place                           0x000000010f56f1fd main + 109
    25  libdyld.dylib                       0x0000000111f7892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

它在
表格视图中崩溃:高度为row路径:
。你在那里做什么?检查你的阵列是否有数据或not@Avi我没有实现tableView:heightForRowAtIndexPath:@KishoreKumar我真的不知道它是什么数组,我认为它是苹果UIKit代码中的一个数组。也许你应该实现这个方法,看看会发生什么。你崩溃的原因完全不同。您的答案有何帮助?我使用了
registernb:forCellReuseIdentifier:
,并将标识符复制粘贴到
dequeueReusableCellWithIdentifier
,但仍然不起作用。