Uitableview 多节崩溃的iOS8表视图——与自动调整大小有关?

Uitableview 多节崩溃的iOS8表视图——与自动调整大小有关?,uitableview,ios8,Uitableview,Ios8,我不知道在我的生活中我有过多少次有益的看法。数百人。但这是我第一次从零开始使用iOS8,事情似乎发生了变化 我正在用虚拟数据构建我的视图层,而我根本无法使多节表工作。它崩溃了,我将在下面显示一个错误 在StoreListController.m中: - (void)viewDidLoad { [super viewDidLoad]; self.tableView.dataSource = self; self.tableView.delegate = self;

我不知道在我的生活中我有过多少次有益的看法。数百人。但这是我第一次从零开始使用iOS8,事情似乎发生了变化

我正在用虚拟数据构建我的视图层,而我根本无法使多节表工作。它崩溃了,我将在下面显示一个错误

在StoreListController.m中:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    self.tableView.estimatedRowHeight = 44.0;
    self.tableView.rowHeight = UITableViewAutomaticDimension;


    self.title = @"Stores";

    self.customers = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
    self.stores = [NSArray arrayWithObjects:@"Ooga", @"Booga", nil];

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return [self.customers count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [self.stores count] ;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [self.customers objectAtIndex:section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"getting myself a cell");
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    cell.textLabel.text = [self.stores objectAtIndex:indexPath.row];

    return cell;
}
如果我从
tableView:numberOfSectionsInTableView:
返回
1
,它会愉快地呈现一个标记为“One”的标题,以及标记为“Ooga”和“Booga”的单元格

但是,如果返回实际存储阵列中的头数,则会得到:

2014-11-12 07:50:57.234 Stanley-FIL[82428:12358084] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0281b946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x024a4a97 objc_exception_throw + 44
    2   CoreFoundation                      0x026febd2 -[__NSArrayI objectAtIndex:] + 210
    3   UIKit                               0x018e9bfc -[UITableViewDataSource tableView:heightForHeaderInSection:] + 50
    4   UIKit                               0x01631139 -[UITableViewController tableView:heightForHeaderInSection:] + 61
    5   UIKit                               0x013f8449 -[UITableView _delegateWantsHeaderForSection:] + 370
    6   UIKit                               0x015b7935 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 169
...
我曾尝试重写它在此处调用的UITableViewDelegate方法(
tableView:heightForHeaderInSection:
),但在查找heightForFooterInSection:)时,我得到了相同的崩溃,如果我实现了它,在查找
tableView:IndentationLevelForRowatineXpath:
时,我会得到相同的崩溃

我以前从未明确实现过所有这些东西。这是怎么回事?我认为这与新的细胞自动大小调整业务有关,但这远远不是“自动”


编辑:然后我继续执行并实现了
tableView:indentationlevelforrowatinexpath:
,它在尝试运行
tableView:heightforrowatinexpath:
时死于相同的错误!我认为这就是使用表格单元格自动调整大小的全部意义所在!我想我误解了一些基本的东西。

你确定你将self.tableView与.xib中的真实一个表连接起来了吗? 我只将此代码添加到您的代码中,它非常适合我(iOS 8.1):

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0;
}