Ios UITableView中NSArray的detailTextLabel出错
我正在创建一个表格视图,其单元格(原型单元格)的细节样式正确。在我拥有的数组上实现self.detailLabelText.text时,当我尝试加载表时,收到一条错误消息。代码如下:Ios UITableView中NSArray的detailTextLabel出错,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在创建一个表格视图,其单元格(原型单元格)的细节样式正确。在我拥有的数组上实现self.detailLabelText.text时,当我尝试加载表时,收到一条错误消息。代码如下: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"Simple
- (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”而终止应用程序,原因:“*-[\uu NSArrayI objectAtIndex:]:索引2超出边界[0..1]”
该表使用主textLabel正确加载,我可以在cell.detailTextLabel=
之后加载字符串,因此我知道我的设置是正确的。我还可以记录我尝试加载的两个阵列,只是不能记录在detailLabelText中
我知道错误消息是由于一个数组的预期长度造成的,我只是不知道是什么或在哪里。对不起,有个基本问题。我是个笨蛋
更新:以下是我的NumberOfRowsin选择方法:
- (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个以上的项。我把最后一个“return10;”放在那里,以防switch语句出现问题,但这似乎并不重要
更新2:当我用静态字符串替换windows1数组时,它们填充在表的详细信息区域中。这很好(尽管我现在似乎对我原来的窗口数组有一些问题) 无论是
windows1
数组还是windows2
数组,其中只有2个项目,并且您的表数据源告诉它有3行要显示。正如Kevin所问,使用您实现的-tableView:numberOfRowsInSection:
方法编辑您的问题,因为问题几乎肯定就在那里。您能为tableView:numberOfRowsInSection:method提出问题吗?在两个委托方法中记录数组内容和数组计数-问题将变得透明。这是真的。阵列windows1尚未完全填充。谢谢。@Craigvu当有人帮助你时,你应该标记回答的问题。否则,你的声誉不会提高,人们也不太可能提供帮助。