TabBarController within the RootViewController of a SplitViewController - ipad

I'd like to develop an iPad app which would be composed of a SplitViewController. I'd like to add a TabBarController in the RootViewController.
I'm at the very beginning of the development. So I've started to simply create a new project, add a SplitViewController via Interface Builder and test the app, no problem of course. Then I've tried to add the TabBarController to the RootView, no problem either via the Interface Builder. The problem I have there is that I can't make the app rotate with the device. I assume that I have to change something in the code but I don't know what :-(
I've noticed that the method shouldAutorotateToInterfaceOrientation is never called when the device rotates.
I'm sorry to ask this question but I'm very new in developping iPad/iPhone apps.
Best regards

UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:annualViewController];
[navigationController1.navigationBar addSubview:imageView1];
[list addObject:navigationController1];
[imageView1 release];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:rootViewController];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navigation bar.png"]];
imageView2.frame = CGRectMake(0, 0, 320, 44);
[navigationController2.navigationBar addSubview:imageView2];
[list addObject:navigationController2];
[imageView2 release];
tabBarController.viewControllers=list;
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
rootViewController.detailViewController = detailViewController;
annualViewController.detailViewController=detailViewController;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:tabBarController, detailViewController, nil];
splitViewController.delegate = detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];

Related

How to get a new view controller instead of parent view for a 1st tab in tabbar view controller?

I struck in a problem with using tab bar controller to my view controller.
Here is my problem
I have a view controller for that i embedded a tab bar controller and i have added four tabs for it and three views are created for the other three tabs, here is my Exact problem. i don't want my 1st tab bar controller select default if i click on my 1st tab i want to show the other view it should not display my parent view where i am showing all the tabs in a parent view.
Please give me some solution how to overcome this. hope my question is clear with details.
Somehow I am able understand your problem. Without posting code sometime its very difficult to identify exact problem.
I am sharing a code with you , assume that App launch a single view controller as "Login View Controller" which is follow by "Dashboard View Controller". Now you want to show TabBar after user login with four different tabs.
Please called below method "setUpTabBar" within Dashboard View Controller ViewDidLoad.
- (void)setUpTabBar
{
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = #"Tab1";
vc1.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:vc1];
nav1 =[self setTrasparentNav:nav1];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = #"Tab2";
vc2.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:vc2];
nav2 =[self setTrasparentNav:nav2];
UIViewController *vc3 = [[UIViewController alloc] init];
vc3.title = #"Tab3";
vc3.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav3 =[[UINavigationController alloc] initWithRootViewController:vc3];
nav3 =[self setTrasparentNav:nav3];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = #[nav1,nav2,nav3];
tabBar.selectedIndex = 0;
tabBar.view.frame = self.view.bounds;
[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];
}
You can change default selected tab bar using tabBar.selectedIndex = 0;
Hope this will help you.
Update (As requested by questionnaire):-
UIView *viewBottom=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height- 60.0, self.view.bounds.size.width, 60.0)];
viewBottom.backgroundColor =[UIColor grayColor];
UIButton *btnAdd =[UIButton buttonWithType:UIButtonTypeSystem];
btnAdd.frame=CGRectMake(10, 10, 60.0, 40.0);
[viewBottom addSubview:btnAdd];
[self.view addSubview:viewBottom];
If you are trying from code, first see how to make uitabbarcontroller in code: How to programmatically add a UITabBarController & UINavigationController in AppDelegate?

Popover with Splitview inside

I want to create programmatically a UIPopoverController with a UISplitViewController inside. The Problem is that the Master-View is overlaying the Detail-View. It seems that the Master-View is popped over the Detail-View. That means i can see both, Master & Detail but the Split is not correct.
Have a look here:
http://i.stack.imgur.com/En70W.png
Any idea how to solve that ?
Thx
.m File
UISplitViewController *customSplitVC = [[UISplitViewController alloc] init];
ListViewController *listViewController = [[ListViewController alloc] init];
listViewController.title = #"Master";
listViewController.content = self.myContent;
UINavigationController *masterNC = [[UINavigationController alloc] initWithRootViewController:listViewController];
masterNC.view.frame = CGRectMake(0, 0, 500, masterNC.view.frame.size.height);
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.title = #"Detail";
UINavigationController *detaillNC = [[UINavigationController alloc] initWithRootViewController:detailViewController];
detaillNC.view.frame = CGRectMake(600, 0, 500, detaillNC.view.frame.size.height);
[customSplitVC setViewControllers:#[masterNC, detaillNC]];
self.popover = [[UIPopoverController alloc] initWithContentViewController:customSplitVC];
self.popover.delegate = self;
self.popover.popoverContentSize = CGSizeMake(1000, 425);
[self.popover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:(UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp) animated:YES];
UISPlitViewController has to be set as the root view controller, so you cannot put it inside a UIPopoverController.
You can try using a 3rd party split view controller though:
https://github.com/Raizlabs/RZSplitViewController

how to add tab bar controller from the second view controller [duplicate]

This question already has an answer here:
Showing login view controller before main tab bar controller
(1 answer)
Closed 9 years ago.
Im beginner to IOS app development learning.
I have a login screen as my first view controller and i need the second view controller to be a tab bar view controller .with 4 different tabs and i have 4 different XIB's for them.
some one help me to go ahead.
Best way you can do is Present the login screen modally when the app starts from your tab bar controller first screen, add code for presenting login screen in viewWillAppear and after login dismiss the screen. You can create TabBarController in appDelegate like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController tabBarController=[[UITabBarController alloc] init];
FirstViewController *firstVC = [[UIViewController alloc] initWithNibName:#"FirstVC" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController: firstVC];
SecondViewController *secondVC = [[UIViewController alloc] initWithNibName:#"secondVC" bundle:nil];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];
tabBarController.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];
tabBarController.selectedIndex=0;
tabBarController.delegate = self;
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:#"Movies" image:[UIImage imageNamed:#"MoviesTAB.png"] tag:1];
[firstVC setTabBarItem:item1];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:#"Music" image:[UIImage imageNamed:#"musicTAB.png"] tag:2];
[seconfVC setTabBarItem:item2];
tabController.tabBar.translucent = NO;
tabController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tintColor = [UIColor whiteColor];
self.window.rootViewController = tabController;
return YES;
}
Best way is use storyboard and there just have one initial UIViewController and from that make segue to UITabBarViewController.
http://youtu.be/a_DCTSTv1Mw
If you want to make it through xib make a UITabBarViewController and add viewControllers to the array of object of that UITabBarViewController's object.
Sample code :
NSMutableArray *arrViewControllers = [[NSMutableArray alloc] init];
UIViewController *tabController;
UIImage *tabImage ;
NSString *tabTitle;
for (int i= 0; i < 3; i++) {
switch (i) {
case 0:
tabController = [[ViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon1.png"];
tabTitle = #"Text";
break;
case 1:
tabController = [[ImageDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon2.png"];
tabTitle = #"Image";
break;
case 2:
tabController = [[TableDemoViewController alloc] init];
tabImage = [UIImage imageNamed:#"icon3.png"];
tabTitle = #"Table";
break;
}
// set the image and title using some properties of UIViewController
tabController.tabBarItem.image = tabImage;
tabController.tabBarItem.title = tabTitle;
//add objects to array
[arrViewControllers addObject:tabController];
[tabController release];
}
_baseController = [[UITabBarController alloc] init];
_baseController.viewControllers = arrViewControllers;
[arrViewControllers release];
go to your appDelegate
1.create a viewController for login screen.
LoginViewController *viewController1 = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
2.create a navigationController with root view your login ViewController.
UINavigationController *nVC = [[UINavigationController alloc] initWithRootViewController:viewController1];
3.make navigationController to root view of window.
self.window.rootViewController = self.nVC;
[self.window makeKeyAndVisible];
Now go to Touch-Up-Inside method of login button in LoginViewController.
1.After validation of password and userId initialise your viewControllers for tabbar and TabbarViewController.
UiViewController ...*yourViewControllers,..,
UITabBarController *YourtabBarController = [[UITabBarController alloc] init];
2.Now add these viewControllers to your tabbarController.
YourtabBarController.viewControllers = #[ YourViewController1,YourViewController2,YourViewController3,......];
3.Finally push this tabbarController to navigationControllere.
[self.navigationController pushViewController:YourtabBarController animated:NO];

TabBarController and NavigationController

I am making an application but I'm still a beginner and I'm trying to get used to the RootViewController and how it should be set.
At the beginning my application launches, I want there to be a View which is not in my tabBarController (which is set to be my rootViewController).
What I am trying to ask is, Can I have another view which is outside my UITabBarController launch first without it being in the tabBarController's items list?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FacebookFeedViewController *facebookClass = [[FacebookFeedViewController alloc] initWithNibName:#"FacebookFeedViewController" bundle:nil];
TwitterFeedViewController *twitterClass = [[TwitterFeedViewController alloc] initWithNibName:#"TwitterFeedViewController" bundle:nil];
LinkedInFeedViewController *linkClass = [[LinkedInFeedViewController alloc] initWithNibName:#"LinkedInFeedViewController" bundle:nil];
FTLFullFeedViewController *masterClass = [[FTLFullFeedViewController alloc] initWithNibName:#"FTLFullFeedViewController" bundle:nil];
/// tab button title
facebookClass.title = #"Facebook";
twitterClass.title = #"Twitter";
linkClass.title=#"LinkedIn";
masterClass.title=#"FTL";
// tab button Images
facebookClass.tabBarItem.image = [UIImage imageNamed:#"facebook_32"];
twitterClass.tabBarItem.image = [UIImage imageNamed:#"twitter_32"];
WelcomeViewController *welcomeClass= [[WelcomeViewController alloc] initWithNibName:#"WelcomeViewController" bundle:nil];
navController = [[ UINavigationController alloc] initWithRootViewController:welcomeClass];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:facebookClass];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:twitterClass];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:linkClass];
UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:masterClass];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController5,navController2,navController3,navController4,nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I know you already selected an answer but all that's doing is pushing a UITabBar view on top of an existing view, not creating a new UITabBarController view. Based on our brief conversation (latest XCode, no StoryBoards, using XIBs) you're going to want to create a xib as a UITabBarController then push it into view...
View *view = [[View alloc] initWithNibName:#"myUITabBarXIB" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];
This will present your XIB file but not on top of the existing view controller when the desired action takes place.
yes! ofcourse you do.
[self.view addsubview:yourTabbar.view];
Hope this will help you.

Best approach to switch between TabBarController and ViewController

I have been trying an app with initial login screen which then takes to a TabBarController.
I want to know whats the best approach to do this any example code would be appreciated. I have tried it but I am unable to switch from ViewController to TabController.
I'm not sure that this is the best way to do it, but it's quick and dirty and works. Present a modal view controller inside your applicationDidFinishLaunchineWithOptions: method. You should replace the #selector with something more appropriate to what you want to do. Background color is for effect only.
- (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];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// ***** The relevant code *****
UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[[viewController view] setBackgroundColor:[UIColor redColor]];
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[dismissButton setFrame:CGRectMake(10, 10, 300, 44)];
[dismissButton setTitle:#"Dismiss" forState:UIControlStateNormal];
[dismissButton addTarget:[self tabBarController] action:#selector(dismissModalViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
[[viewController view] addSubview:dismissButton];
[[self tabBarController] presentViewController:navigationController animated:NO completion:nil];
return YES;
}
I normally wouldn't like to put this sort of code in the app delegate, but if it's a one-time thing like login details, maybe it's ok.
Assume your root view controller is also your login view.
Now from your root view controller, you can present the tab bar controller a number of ways. One way is to just call the presentViewController method from the root view controller.
Setup
From within the root view controller, sometime before presenting the tab bar, set it up:
myTabBarViewController = [[MyTabBarViewController alloc] init];
[myTabBarViewController setModalPresentationStyle:UIModalPresentationFullScreen];
[myTabBarViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[myTabBarViewController setRootTabBarDelegate:self];
Presentation
When you are ready to present, just call this:
[self presentViewController:myTabBarViewController animated:YES completion:nil];
Notes
The view controller hierarchy looks like this:
AppDelegate
L RootViewController
L MyTabBarController

Resources