开发者

UITableView detail descripton error

I am using following way to send data to detail view controller for e.g if i have 3 rows in one section it works fine for row one but not for row two it gives error index beyond

- (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;
//a开发者_StackOverflow社区ffecteddate = [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];


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;

}


Well the problem is pretty obvious, whatever array you are accessing doesnt have elements in those indexes and so you get index beyond bounds, what you should do is check which array it is and check the contents of it make sure you have put all the information needed in the array...Or go to the rowForSection method of tableviewdatasource delegate and check why its returning an out of bound number (probably you have it hard coded or are querying the wrong array for the section)...

Daniel

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜