Question

I am trying to build an application that upon opening you will see a table view, with several elements. After you click on an element you will be taken to a new view which is a tab bar controller. I have created a navigation controller as my root view controller and what I am trying to figure out is do I need to pass off the root view controller's function from the navigation controller element to the tab bar controller? And then the tab bar controller does the work? I have been reading

Beginning IPhone 4 Development: Exploring the IOS SDK [Book] by David Mark, Jack Nutting, Jeff LaMarche

Chapter 7 gives a good example of how to use a tab bar controller but how can I pass the functions of the navigation controller to the tab bar controller that I am using?

Was it helpful?

Solution

You can use navigation controller at root and after that tab bar controller as following way:-

this one is yr application delegate's .h file:-

@interface NavTabDemoAppDelegate : NSObject <UIApplicationDelegate>
{
   IBOutlet  UINavigationController *navController;
    IBOutlet UITabBarController *TabBar;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet  UINavigationController *navController;
@property (nonatomic, retain) IBOutlet UITabBarController *TabBar;

this one is yr app delegate's .m file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window addSubview:navController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

drag and drop navigation controller and tab bar controller from library to main window.xib and set outlets to application delegates

In yr tableview view controller's .h file, create object of yr delegate as follows

NavTabDemoAppDelegate *appdelegate;

in .m file of yr tableview controller at viewdidload

appdelegate = [[UIApplication sharedApplication] delegate];

just write this at tableview view controller's DidSelectRowAtIndexPath

[self.navigationController pushViewController:appdelegate.TabBar animated:YES];

done!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top