I have a Tab Bar with a navigation table view. My app crashes when I select a cell on my table view. I want a new viewcontroller to open when a cell is selected. My guess is that I am not pushing it correctly when didselectrowatindexpath is called. The app stays hung up for a few seconds then closes.
Does anything catch your eye with this code? Or do you have any sample code? I am using Xcode 3 with simulator 4.3.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (self.vailViewController == nil) {
VailViewController *vailView = [[VailViewController alloc] initWithNibName:@"View" bundle:nil];
self.vailViewController = vailView;
[vailView release];
}
vailViewController.title = [NSString stringWithFormat:@"%@", [resortsArray objectAtIndex:row]];
Ski_AdvisorAppDelegate *delegate = (Ski_AdvisorAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.resortsNavController pushViewController:vailViewController animated:YES];
[self.navigationController pushViewController:vailViewController animated:YES];
}
Thanks a lot!
In this block of code is your view file actually named “View.xib” because if not this is your crash. With this error message
So if you want to load this with initWithNibName and your files are named as such:
VailViewController.h
VailViewController.m
VailViewController.xib
you need:
However if it is a standard UIViewController subclass you should only need to do:
The above works if you just created a UIViewController subclass in Xcode and didn’t change anything. The view controller knows how to load it’s own view. If you had it create an .xib file for you and you deleted something in it or just arn’t sure make sure the File’s Owner is wired up to the root view in the .xib file in interface bulder.
I hope that helps.
Edit:
The error in your comments:
is coming these two lines in your code:
I should ask if these are two different navigation controllers? if so why do they need the exact same view controller pushed to them?
I would remove one of them and then it should push the view controller without error.