I am trying to change a tabbed application on xcode 4 to incorporate a navigation controller without storyboard. The 1st tab contains a table. This is the one that needs to be navigable.
Here is FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *storeDetailsTable;
}
@property (nonatomic, retain) UITableView *storeDetailsTable;
@property (nonatomic, strong) NSDictionary *resultData;
@property (nonatomic, strong) NSMutableArray *populatedStoreArray;
@property (nonatomic, strong) NSMutableArray *images;
@end
Here's the NavController.h:
#import <UIKit/UIKit.h>
@interface NavController : UINavigationController
@property (nonatomic,retain) IBOutlet UINavigationController * navController;
@end
So, I'm using NavController as a UIViewControllerSubclass and then changed it to the above.
The AppDelegate.h:
#import <UIKit/UIKit.h>
@class NavController;
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
IBOutlet NavController *navController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@property (strong, nonatomic) IBOutlet NavController *navController;
@end
And AppDelegate.m:
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "NavController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
navController = [[NavController alloc] initWithNibName:@"NavController" bundle:nil];
// UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Now when I build and run it, I see 2 tabs. But the first tab is just a blank black screen depicting the Navigation controller but there's no tableview as should be.
Is there something I have missed?
Thanks..
In your code I can't see that you're initing the FirstViewController class and making it known to the NavController. The NavController needs to init with a RootViewController, like:
NavController *myNavController = [[NavController alloc] initWithRootViewController:yourFirstViewController];
A good place to find more info is at: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html