UITableView详细描述错误

时间:2011-08-26 03:35:10

标签: iphone objective-c

我正在使用以下方式将数据发送到详细视图控制器,例如,如果我在一个部分中有3行,则它对第一行工作正常,但对于第二行则不然,它提供的错误索引超出

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //  [tableView deselectRowAtIndexPath:indexPath animated:YES];  



    Book1*aBook;

if(indexPath.section == 0)
{
    aBook=[appDelegate.books1 objectAtIndex:indexPath.row];


    int count=[appDelegate.books1 count];


}

else if(indexPath.section == 1)
{

    aBook=[appDelegate.books2 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 2)
{

    aBook=[appDelegate.books3 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 3)
{

    aBook=[appDelegate.books4 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 4)
{
    aBook=[appDelegate.books5 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 5)
{
    aBook=[appDelegate.books6 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 6)
{
    aBook=[appDelegate.books7 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 7)
{
    aBook=[appDelegate.books8 objectAtIndex:indexPath.row];

}

else if(indexPath.section == 8)
{
    aBook=[appDelegate.books9 objectAtIndex:indexPath.row];

}
else if(indexPath.section == 9)
{
    aBook=[appDelegate.books10 objectAtIndex:indexPath.row];

}










NSString*eventId=aBook.eventId; 
NSLog(eventId);

//  int next= [aBook.affecteddate intValue];
NSString*affecteddate = aBook.affecteddate;
//affecteddate = [NSString stringWithFormat:@"%d", aBook.affecteddate];
NSLog(affecteddate);


DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
dvController.eventId=eventId;
dvController.affecteddate=affecteddate;

[self.navigationController pushViewController:dvController animated:YES];
[dvController release];

2 个答案:

答案 0 :(得分:1)

I think you did'nt write the following method like below: 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

int count;
if(section == 0)
{

  count=[appDelegate.books1 count];

}

if(section == 1)
{

  count=[appDelegate.books2 count];

}
if(section == 2)
{

  count=[appDelegate.books3 count];

}

//similarly all+

return count;

}

答案 1 :(得分:0)

问题很明显,无论你访问的是什么数组都没有这些索引中的元素,所以你得到索引超出界限,你应该做的是检查它是哪个数组并检查它的内容确保你已经把数组中所需的所有信息...或者转到tableviewdatasource委托的rowForSection方法,并检查为什么它返回一个超出范围的数字(可能你有硬编码或查询该部分的错误数组)... < / p>

丹尼尔