Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表格视图中的表格视图_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 表格视图中的表格视图

Ios 表格视图中的表格视图,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个静态UItableView。在其中一个单元格中,我有一个动态原型UITableView。以下是我实现的代码: 在viewDidLoad: self.tagsArray = [[NSArray alloc] initWithObjects:@"hey", @"what", @"ola", @"dada", @"hoster", @"umi", nil]; - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

我有一个
静态UItableView
。在其中一个
单元格中,我有一个
动态原型UITableView
。以下是我实现的代码:

viewDidLoad:

self.tagsArray = [[NSArray alloc] initWithObjects:@"hey", @"what", @"ola", @"dada", @"hoster", @"umi", nil];

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.tableView == tableView ? 2 : 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.tableView == tableView)
        return (section == 0) ? 3 : 2;
    else
        return [self.tagsArray count];
}

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

    if (self.tableView == tableView) {
        cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    }
    else {
        cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        [cell.textLabel setText:self.tagsArray [indexPath.row]];
    }

    return cell;
}
当我运行应用程序时,一切正常。但是,当我开始在内部
表视图(动态原型视图)上滚动时,我得到以下错误:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001012a7c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000100f40bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010119e17e -[__NSArrayI objectAtIndex:] + 190
    3   UIKit                               0x0000000101e12132 -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 106
    4   UIKit                               0x00000001019dc1f9 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1711
    5   UIKit                               0x000000010195a68e +[UIView(Animation) performWithoutAnimation:] + 65
    6   UIKit                               0x00000001019dbb3b -[UITableView _configureCellForDisplay:forIndexPath:] + 312
    7   UIKit                               0x00000001019e3a41 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 533
    8   UIKit                               0x00000001019c2248 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2853
    9   UIKit                               0x00000001019d88a9 -[UITableView layoutSubviews] + 210
    10  UIKit                               0x0000000101962a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    11  QuartzCore                          0x0000000100934ec2 -[CALayer layoutSublayers] + 146
    12  QuartzCore                          0x00000001009296d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    13  QuartzCore                          0x0000000100929546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    14  QuartzCore                          0x0000000100895886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    15  QuartzCore                          0x0000000100896a3a _ZN2CA11Transaction6commitEv + 462
    16  QuartzCore                          0x00000001008970eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    17  CoreFoundation                      0x00000001011daca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    18  CoreFoundation                      0x00000001011dac00 __CFRunLoopDoObservers + 368
    19  CoreFoundation                      0x00000001011d0a33 __CFRunLoopRun + 1123
    20  CoreFoundation                      0x00000001011d0366 CFRunLoopRunSpecific + 470
    21  GraphicsServices                    0x000000010510da3e GSEventRunModal + 161
    22  UIKit                               0x00000001018e2900 UIApplicationMain + 1282
    23  myApp                               0x00000001004cf51f main + 111
    24  libdyld.dylib                       0x0000000102cfe145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我不知道上面的错误是什么意思,但我认为出于某种原因,它没有创建新的
单元格
,正因为如此,它与要显示的
单元格
的数量存在冲突,因此它会因上面的错误而崩溃


为什么内部的
表格视图不创建新的
单元格
,我可以做些什么来修复它?

错误告诉您的是,您试图访问一个不存在的元素


您的数据数组只有2个元素,但您正在硬编码要创建的单元格数量(3),因此当它寻找第3个元素来创建单元格时,它会崩溃,因为它不存在。

谢谢您的回答!!我的数组有5个对象。这是
self.tagsArray
嵌套表视图可能会变得奇怪。看起来UITableViewDataSource tableView:IndentationLevelForRowatineXpath:正在执行越界访问,该方法可能在超类中实现。我想知道重构使不同的表视图具有不同的委托实现是否会有所帮助。