Hi,
I have a UITableView which has 2 rows in it, and I want to use pushViewController for both rows, but I want to push a different view in depending on what row was selected.
I want to do this by specifying a method based on the row selected, like so:
But it doesn't work. It says that "'UIViewController' may not respond to '-pushViewControllerFirstView'"
However, if I remove the methods and insert the code manually, like this, it works:
So I believe it's just the path for what I'm telling to receive the methods that isn't right? Can anyone help? I know the second way works but I think it might be better practice to do it the first way. Thanks in advance.
I have a UITableView which has 2 rows in it, and I want to use pushViewController for both rows, but I want to push a different view in depending on what row was selected.
I want to do this by specifying a method based on the row selected, like so:
Code:
-(void)pushViewControllerFirstView:(id)sender {
FirstView *firstView = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
[self.navigationController pushViewController:firstView animated:YES];
[firstView release];
}
-(void)pushViewControllerSecondView:(id)sender {
SecondView *secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
}
// This is inside didSelectRowAtIndexPath...
if (indexPath.row == 0){
[self.parentViewController pushViewControllerFirstView];
} else if (indexPath.row == 1){
[self.parentViewController pushViewControllerSecondView];
}
But it doesn't work. It says that "'UIViewController' may not respond to '-pushViewControllerFirstView'"
However, if I remove the methods and insert the code manually, like this, it works:
Code:
// This is inside didSelectRowAtIndexPath...
if (indexPath.row == 0){
FirstView *firstView = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
[self.navigationController pushViewController:firstView animated:YES];
[firstView release];
} else if (indexPath.row == 1){
SecondView *secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
}
So I believe it's just the path for what I'm telling to receive the methods that isn't right? Can anyone help? I know the second way works but I think it might be better practice to do it the first way. Thanks in advance.