我正在使用 Detail Right 样式的单元格(原型单元格)创建表格视图。在数组上实现 self.detailLabelText.text 时,我在尝试加载表时收到一条错误消息。下面是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:simpleTableIdentifier];
}
switch (pickerSelection)
{
case 0:
cell.textLabel.text = [visitList1 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [windows1 objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [visitList2 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [windows2 objectAtIndex:indexPath.row];
break;
}
return cell;
}
我收到错误消息:
由于未捕获的异常“NSRangeException”而终止应用程序,原因:“ * -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]”
该表使用主 textLabel 正确加载,之后我可以加载一个字符串,cell.detailTextLabel =
因此我知道我的设置是正确的。我也可以 NSLog 我试图加载的两个数组,只是不在 detailLabelText 中。
我知道错误消息必须与数组的预期长度有关,我只是不知道是什么或在哪里。对不起,一个基本的问题。我是菜鸟。
更新:这是我的 numberOfRowsInSelection 方法:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (pickerSelection)
{
case 0:
return [visitList1 count];
return [windows1 count];
break;
case 1:
return [visitList2 count];
return [windows2 count];
break;
}
return 10;
}
每个数组都有超过 3 个项目。我扔了最后一个“return 10”;在那里以防万一 switch 语句不能正常工作,但这似乎并不重要。
更新 2:当我用静态字符串替换我的 windows1 数组时,它们会填充在表格的详细信息区域中。太好了(尽管我现在的原始窗口数组似乎有某种问题)。