So, i have 3 section like i said in my previous question, "A", "B", "C", for example.
This is the code i'm using:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row)
{
case 0:
[self.navigationController pushViewController:[[[FirstViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 1:
[self.navigationController pushViewController:[[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
etc..
}
}
This is my problem: in "A" i have 6 elements. If i use the switch from 0 to 5, it pushes out the right View Controllers. But when i have to push out the View Controllers for the "B" section, that contains another 9 elements, i go ahead with the counter (so case 7,8 etc),it starts again to show the controllers from the begin (it pushes out again FirstViewController" etc). Same story for "C" section. How to solve this?
I'm hating grouped tables, damn.
Edit: new code, looping
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section)
{
case 0:
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:[[[FirstViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 1:
[self.navigationController pushViewController:[[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
}
case 1:
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:[[[ThirdViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 1:
[self.navigationController pushViewController:[[[FourthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 2:
[self.navigationController pushViewController:[[[FifthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
}
case 2:
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:[[[SixthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 1:
[self.navigationController pushViewController:[[[SeventhViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
}
}
}
I've obviously cut the code, too long otherwise.
Edit 2:
Worked! Sergio's answer was right, but i put an if (indexPath.section == 0)
instead of switch (indexPath.section){}