I have searched a lot about this topic and I can’t get this code work. When I execute it, it only shows my test NSLog but the code to go from one view to another doesn’t do anything. Here you have the following code:
//FirstViewController.h
#import <UIKit/UIKit.h>
#import "StationDetailsViewController.h"
@interface FirstViewController : UIViewController{
NSArray *ListaEstaciones;
NSArray *ListaID;
}
@property (nonatomic, retain) NSArray *ListaEstaciones;
@property (nonatomic, retain) NSArray *ListaID;
@end
//FirstViewController.m
#import "FirstViewController.h"
#import "StationDetailsViewController.h"
@implementation FirstViewController
@synthesize ListaEstaciones;
@synthesize ListaID;
//...
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Pushing...");
StationDetailsViewController *controller = [[StationDetailsViewController alloc] initWithNibName:@"StationDetailsViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
@end
I have tried lots of tutorials and my book but I don’t know what is wrong. Thanks a lot, guys.
EDIT: Reading your answers I found that the error is on AppDelegate.m where rootViewController is defined.
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I don’t know what to edit here to make this:
[[self navigationController] pushViewController:controller animated:YES];
work properly.
i think the problem is in [self navigationController] .. put a break point on this line of code and probaly you will find its value = nil cuz of that you are not having your detail controller .. you could solve this like that
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:yourMainViewControllerInstance];This The appDelegate Code :