Reputation: 195
I'm currently working on an app that retrieves a list of films from the rotten tomatoes API and displays them in a table. I'd like a UIViewController to show up once I tap on a row so I can display a detailed page.
Here's the code I have for my didSelectRowAtIndexPath.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
//UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self]; // This line of code throws an exception for some reason.
[self.navigationController pushViewController:detailViewController animated:YES];
}
It might be that I haven't slept for a very long time but I can't for the life of me figure out where I'm going wrong.
PS. I'm using arc.
Upvotes: 1
Views: 302
Reputation: 6718
Write these properties in AppDelegate.h file
@property (strong, nonatomic) YourFirstViewController *yourFirstController;
@property (nonatomic, retain) UINavigationController *navigationControl;
Write this code in AppDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.yourFirstViewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.yourFirstViewController];
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
I think it will be helpful to you.
Upvotes: 0
Reputation: 3406
Are you sure your navigation controller is initialized?
If not your are properly missing something like this in the place where you construct your UIViewController
:
MyVc = [[MyVC alloc] initWithNibName:@"MyVC" bundle:nil];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:myVc];
[_window addSubview:navCon.view];
Upvotes: 2