IOS Adding a TabBar Controller to a view - ios

My IOS app has a login sequence that cannot be modified, once the sequence is complete I do the following in the app delegate
- (UIViewController*)newRootViewController {
NViewController *nView = [[NViewController alloc]
initWithNibName:#"NViewController"
bundle:nil];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:nView];
[nView release];
return navVC;
}
Once in nView is it possible to add a tab bar controller or how can I replace nView with a tab bar controller.

You can create a UITabBarController then add your NViewController and other controllers to the tab bar.
NViewController *nView = [[NViewController alloc]
initWithNibName:#"NViewController"
bundle:nil];
//Create my tab bar
UITabBarController* myTabController = [[UITabBarController alloc]init];
//Add my tabs
NSArray* tabs = [[NSArray alloc]initWithObjects:nView, nil];
[myTabController setViewControllers:tabs];

Related

navigating to ViewControllers that aren't on the UITabBar

I started using UITabBarController and it is great.
The thing is I have a few views that aren't accessed from the UITabBar
(either presented modal programatically or we want to have a button on the top to jump to them)
The thing is that I want to retain the Tab bar visible in these views.
From my understanding mixing presentViewController and UITabBarController is problematic.
How can I do that? Can I have "hidden" tab bar elements I can reference programatically?
Just to clarify with an example:
Views A,B,C,D are in the tab bar - via the storyboard - everything is peachy.
I NEED to have views E and F clickable from the top navigation (please don't suggest a sliding TabBar or a multiple line UITabBar).
I could just jump to E and F but I want the UITabBar to still be visible so the user can jump from E to A for example.
Just use the good old UINavigationController for every tab and just use [self.navigationController pushViewController:A animated:YES];
That's how the setup looks in code:
SGTabBarViewController *rootVC = [[SGTabBarViewController alloc] init];
SGFirstTabViewController *firstVC = [[SGFirstTabViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
SGSecondTabViewController *secondVC = [[SGSecondTabViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
SGThirdTabViewController *thirdVC = [[SGThirdTabViewController alloc] init];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
SGForuthTabViewController *fourhtVC = [[SGForuthTabViewController alloc] init];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:fourhtVC];
rootVC.viewControllers = #[navController1, navController2, navController3, navController4];
self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];
If you want your UITabBar visible on every VC you push just use hidesBottomBarWhenPushed = NO; on it.
However, there is no way to have UITabBar visible on views presented modally.

How to push rootviewcontroller in Ios

I push new StatusViewController(i created UITabbarViewController programmically in it) from rootviewController (UInavigation controller). Now, i want to click on logout button, it push rootviewcontroller but i used below code, it push rootviewcontroller fine but it still tabbar at the bottom.
This code to call rootviewcontroller:
LoginTab *loginView = [[LoginTab alloc] init];
[self.navigationController pushViewController:loginView animated:YES];
[loginView release];
And this code is created UItabbarcontroller in StatusViewController:
self.tab=[[UITabBarController alloc]init];
UploadTab *uploadview=[[UploadTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *uploadTabItem = [[[UINavigationController alloc] initWithRootViewController: uploadview] autorelease];
uploadview.title=#"Uploading";
uploadview.tabBarItem.image=[UIImage imageNamed:#"Uploading.png"];
self.title = #"FirstViewControllerTitle";
//SecondViewController
ConvertTab *convertView=[[ConvertTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *convertTabItem = [[[UINavigationController alloc] initWithRootViewController: convertView] autorelease];
convertView.title=#"Convert";
convertView.tabBarItem.image=[UIImage imageNamed:#"Convert.png"];
//ThirdViewController
CompletedTab *completedView=[[CompletedTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *completedTabItem = [[[UINavigationController alloc] initWithRootViewController: completedView] autorelease];
completedView.title=#"Completed";
completedView.tabBarItem.image=[UIImage imageNamed:#"Completed.png"];
UIBarButtonItem * LogoutItem= [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"Logout.png"] style:UIBarButtonItemStylePlain target:self action:#selector(logout)];
self.navigationItem.rightBarButtonItem = LogoutItem;
self.tab.viewControllers=[NSArray arrayWithObjects:uploadTabItem,convertTabItem, completedTabItem, nil];
// [self.view insertSubview:self.tab.view belowSubview: uploadview.view];
[self presentModalViewController:self.tab animated:NO];
You can see this image :
Use popToRootViewControllerAnimated method instead of pushViewController:
[self.navigationController popToRootViewControllerAnimated:animated];
Your hierarchy does not seem correct. Your tab bar controller should be the root view controller. For each tab, you can have a navigation controller which has its own controllers to push and pop. That said, your tab bar will always be visible since that is the behavior that is expected when you have a tab bar based app. If you want to present a view which does not show a tab bar, you will need to present that view controller as a Modal view controller on top of your tab bar controller.

Can I change the first screen of tab item programatically?

Can I change the first screen of a tab item programatically?
For example,
When user is in Tab A, upon tapping a button there, user will be
navigated to Tab C with Screen 1 However, when user is in Tab C, upon
tapping a button here, user will be navigated to Tab C with Screen 2.
Therefore, both screen 1 and 2 will be the first screen of Tab C
depend on where the user comes from.
Can I achieve something like that?
Thanks!
Based on this post How to replace a navigation root controller by tab bar controller in existing iphone app , can change the view controllers by this code:
NSMutableArray * viewControllers = [[NSMutableArray alloc]init];
FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];
SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];

App Organization for iOS

I have experience in C and C++, but near zero experience in Objective C, or Xcode4.
Im looking to create an app with a Tab bar, Navigation Bar, and Table Views. Based on the knowledge i have i assume i start from the top and drill down to the root?
First
Create myTableViewController class that will dynamically create tableview content and push its created view onto the navigation controller.
Then...
Create myNavController class that holds myTableViewController. with a method that creates a new item for myTableViewController.
Then...
Create the Tab Bar Controller that has the above as one of its tabs in an array along with some other tabs, set the tab bar controller as the root controller and display it to the window.
Is this the right direction to be thinking? Or am i horribly off course?
I have an app with these same requirements. It's got a UITabBar, and in the different tabs each UITableViewController has a UINavigationController navigation bar at the top.
Here's how my App Delegate handles this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Create the UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
//Create the view controllers for our tabs
UITableViewController *vc1 = [[UITableViewController alloc] init];
UITableViewController *vc2 = [[UITableViewController alloc] init];
UITableViewController *vc3 = [[UITableViewController alloc] init];
UITableViewController *vc4 = [[UITableViewController alloc] init];
UITableViewController *vc5 = [[UITableViewController alloc] init];
//Create the Navigation Controllers for these views
UINavigationController *nc1 = [[[UINavigationController alloc]
initWithRootViewController:vc1] autorelease];
UINavigationController *nc2 = [[[UINavigationController alloc]
initWithRootViewController:vc2] autorelease];
UINavigationController *nc3 = [[[UINavigationController alloc]
initWithRootViewController:vc3] autorelease];
UINavigationController *nc4 = [[[UINavigationController alloc]
initWithRootViewController:vc4] autorelease];
UINavigationController *nc5 = [[[UINavigationController alloc]
initWithRootViewController:vc5] autorelease];
//Make an array containing the view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nc4, nc5, nil];
//The NSArray has retained these controllers, we can now release them.
[vc1 release];
[vc2 release];
[vc3 release];
[vc4 release];
[vc5 release];
[nc1 release];
[nc2 release];
[nc3 release];
[nc4 release];
[nc5 release];
//Assign the view controllers to the tab bar.
[tabBarController setViewControllers:viewControllers];
//Set tabBarController as rootViewController of window
[self.window setRootViewController:tabBarController];
//The window retains tabBarController, we can release our reference
[tabBarController release];
[self.window makeKeyAndVisible];
return YES;
}
Enjoy!

How do you add a "Back button" on the iPad's SplitViewController popover Navigation bar?

How do you add the Navigation items on the popover (left pane) of the iPad's splitview? This is where the mailboxes/inbox/drafts part of the navigation is in the iPad's builtin email application.
Make the UISplitViewController’s “master” pane a UINavigationController, then just push UIViewControllers on it that have navigationItems.
Here’s a sample setup:
UIViewController *masterController = [[MyCustomMasterController alloc] init…];
[[masterController navigationItem] setTitle:#"Root"];
UINavigationController *navController =
[[UINavigationController alloc] initWithRootController:masterController];
UIViewController *detailController [[MyCustomDetailController alloc] init…];
UISplitViewController *splitView = [[UISplitViewController alloc] init];
[splitView setViewControllers:[NSArray arrayWithObjects:navController,
detailController,
nil]];
And then later on:
UIViewController *subController = [[MyCustomSubController alloc] init…];
[[masterController navigationController] pushViewController:subController
animated:YES];
Pushing a new UIViewController to the UINavigationController’s stack will cause a back button titled “Root” to appear for the MyCustomMasterController view.

Resources