iPhone X Tab Bar and Nav Bar Issue - uitabbarcontroller

I have this complete app build programmatically right from beginning. The project was started on an old Xcode may be Xcode 6. I am currently building on Xcode 6. My Project has Objective-C and Swift files communicating with each other. The problem I am having is because it is built programmatically, I cannot just go into the storyboard and set use safe areas layout.
My Tab Bar Images on Xcode 9.2 are going crazy and also the nav bar. I want to fix the images as well as height of the tab bar.
Here is the code in AppDelegate for adding tabbarcontroller.
- (void)setupView {
UIViewController *firstViewController = [[UIViewController alloc]init];
firstViewController.view.backgroundColor = UIColor.redColor;
firstViewController.title = #"First View";
firstViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
UIViewController *secondViewController = [[UIViewController alloc]init];
secondViewController.view.backgroundColor = UIColor.blueColor;
secondViewController.title = #"Second View";
secondViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
UIViewController *thirdViewController = [[UIViewController alloc]init];
thirdViewController.view.backgroundColor = UIColor.purpleColor;
thirdViewController.title = #"Third View";
thirdViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];
UIViewController *fourthViewController = [[UIViewController alloc]init];
fourthViewController.view.backgroundColor = UIColor.greenColor;
fourthViewController.title = #"Fourth View";
fourthViewController.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
UINavigationController *fourthNavController = [[UINavigationController alloc]initWithRootViewController:fourthViewController];
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tabBarController.tabBar invalidateIntrinsicContentSize];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
tabBarController.delegate = self;
[tabBarController.view setNeedsLayout];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
}
I have added the iPhone X Splash screen which made the complete app to go
I have researched enough but not able to find a solution.

You apparently missed this line [[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tabBarController.tabBar invalidateIntrinsicContentSize];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, fourthNavController, nil];
/* Enter this line */
[[tabBarController view] setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
tabBarController.delegate = self;
[tabBarController.view setNeedsLayout];
I tried with your code and got the result:
Here is a screenshot:

Related

How can i set the view Controller within the screen area with tabbar controller

I have created the tabbar controller programmatically. Below is my code of Tab bar controller.
RecordedAudioListViewController *recordedAudioListViewController = [[RecordedAudioListViewController alloc] initWithNibName:#"RecordedAudioListViewController" bundle:nil];
recordedAudioListViewController.tabBarItem = [[UITabBarItem alloc]initWithTitle:#"Recording" image:spongebob tag:0];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:recordedAudioListViewController];
firstNavController.navigationBarHidden = YES;
RecordViewController *recordViewController = [[RecordViewController alloc]initWithNibName:#"RecordViewController" bundle:nil];
recordViewController.tabBarItem = [[UITabBarItem alloc]initWithTitle:#"Record" image:patrick tag:1];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:recordViewController];
secondNavController.navigationBarHidden = YES;
SettingViewController *settingViewController = [[SettingViewController alloc]initWithNibName:#"SettingViewController" bundle:nil];
settingViewController.tabBarItem = [[UITabBarItem alloc]initWithTitle:#"Setting" image:spongebob tag:2];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:settingViewController];
thirdNavController.navigationBarHidden = YES;
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, nil];
tabBarController.delegate = self;
tabBarController.selectedIndex = 1;
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
In Below image, you can see view controller goes out of screen on top side.

How to use slide menu (Same as facebook menu) and tabbar together

Please check below code . I need to implement tabbar and facebook slide menu together.
tabBarController.delegate = self;
self.leftController = [[LeftViewController alloc] initWithNibName:#"LeftViewController" bundle:nil];
RightViewController* rightController = [[RightViewController alloc] initWithNibName:#"RightViewController" bundle:nil];
// ViewController *centerController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
FirstViewController *centerController = [[FirstViewController alloc] initWithNibName:#"FirstView" bundle:nil];
self.centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.centerController
leftViewController:self.leftController
rightViewController:rightController];
deckController.rightSize = 100;
self.window.rootViewController = deckController;
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
Since it looks like you're using the IIViewDeckController, look at its automaticallyUpdateTabBarItems property.

Rotate interface with UITabBarController in Xcode 4.5(iOS6)?

I've created a new "Tab Bar project" with the new Xcode 4.2. The "new" way to work with UITabBar is different: Xcode doesn't create a xib file (with the UITabBarController), but it does everything via code. Ok, let's do it.
So my code in didFinishLaunchingWithOptions is this:
UIViewController *viewController1, *viewController2, *viewController3;
UINavigationController *nav1, *nav2, *nav3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[gemboy_iphone alloc] initWithNibName:#"vc1" bundle:nil];
viewController2 = [[concerti_iphone alloc] initWithNibName:#"vc2" bundle:nil];
viewController3 = [[discografia_iphone alloc] initWithNibName:#"vc3" bundle:nil];
nav1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
nav2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
nav3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
}
else {
//same thing for the iPad version
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nil];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.splash.view];
[self.window makeKeyAndVisible];
return YES;
And it works.
My three .m files vc1.m, vc2.m and vc3.m (and also my iPad UIViewControllers) has this method
- (BOOL)shouldAutorotate {
return YES;
}
The problem is that when I rotate the iPhone, it's not rotating.
Any one please tell me where i done mistake and any thing wrong?
You should subclass the uitabbarcontroller and implemetn
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}

UITabBar inside Master View

I need to create an app with a Split View but I need to add a tab bar in the Master side of the split, I've read some stuff in this forum but I just can't get it right.
I understand that when you have a split view you actually handle two view controllers the master and the detail so, to my understanding, if I need a tab bar in the master side I have to call the master from the appDelegate and inside this master I can set it up as a Tab Bar controller but either I have a complete misconception or I'm just implementing it wrong.
Here's what I'm doing in the appDelegate, as you can see I'm loading another VC than the master VC that comes with the template, my first question is if I have to load a VC or just an NSObject with the tab bar protocol?:
WTDInitialViewController *initialViewController = [[WTDInitialViewController alloc] initWithNibName:#"WTDInitialViewController" bundle:nil];
UINavigationController *initialNavigationController = [[UINavigationController alloc] initWithRootViewController:initialViewController];
WTDDetailViewController *detailViewController = [[WTDDetailViewController alloc] initWithNibName:#"WTDDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:initialNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
Now, this is what I do in the so called VC
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSMutableArray *vcArray = [[NSMutableArray alloc] initWithCapacity:1];
_tabBarController = [[UITabBarController alloc] init];
WTDMasterViewController *masterViewController = [[WTDMasterViewController alloc] initWithNibName:#"WTDMasterViewController_iPad" bundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
_navigationController.navigationBar.barStyle = UIBarStyleBlack;
[vcArray addObject:_navigationController];
_tabBarController.viewControllers = vcArray;
_tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
self.tabBarController.selectedIndex = 0;
[_window addSubview:_tabBarController.view];
[_window makeKeyAndVisible];
}
return self;
It may be a stupid question but I hit a dead end so, any help will be much appreciated
First, I'm assuming you are creating SplitView for ipad. It's initial comes with MasterViewController and DetailViewController. And the MasterViewController is UITableview base, now you want to implement Tabbar base instead, then just call do this in ViewWillAppear of MasterViewController.
UIViewController *viewController1 = [[[YourTabView1 alloc] initWithNibName:#"YourTabView1" bundle:nil]autorelease];
//If you want the view support Navigation then do this
UINavigationController *tab1 = [[[UINavigationController alloc] initWithRootViewController:viewController1]autorelease];
UIViewController *viewController2 = [[[YourTabView2 alloc] initWithNibName:#"YourTabView2" bundle:nil]autorelease];
UINavigationController *tab2 = [[[UINavigationController alloc] initWithRootViewController:viewController2]autorelease];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,nil];
[self presentModalViewController:tabbarController animated:YES];
I think this should work(but I didnt test the code).

IOS TabBarController Questions

TabBar will be about 2 question. I am using a combination of a TabBar and NavigationController. As the following link.
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html
Question 1:
I would like to appear before a TabBar to another ViewController. Several checks are here to do. (For example, Facebook login) If the prerequisites are met, tabbar will be visible. How do I do?
Question 2:
TabBar screen icon that appears in the middle of the first TabBar want it to be. The following code sequence also affects the order of TabBarItem.
self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];
Thank you.
Okan Sahin
For those who have the same problem:
I'm using Xcode 4.2. I have created Tabbed App.
Answer 1:
For loading screen,
I created a new ViewController.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewControllerLoading = [[LoadingViewController alloc] initWithNibName:#"LoadingViewController" bundle:nil];
self.window.rootViewController = viewControllerLoading;
[self.window makeKeyAndVisible];
return YES;
}
LoadingViewController.h
#interface LoadingViewController : UIViewController <UITabBarControllerDelegate>
#property (strong, nonatomic) UITabBarController *tabBarController;
#end
LoadingViewController.m
UIViewController *viewControllerFriends = [[FriendsViewController alloc] initWithNibName:#"FriendsViewController" bundle:nil];
UINavigationController* navController1 = [[UINavigationController alloc]
initWithRootViewController:viewControllerFriends];
UIViewController *viewConrollerMessages = [[MessagesViewController alloc] initWithNibName:#"MessagesViewController" bundle:nil];
UINavigationController* navController2 = [[UINavigationController alloc]
initWithRootViewController:viewConrollerMessages];
UIViewController *viewControllerWorld = [[WorldViewController alloc] initWithNibName:#"WorldViewController" bundle:nil];
UINavigationController* navController3 = [[UINavigationController alloc]
initWithRootViewController:viewControllerWorld];
UIViewController *viewControllerCheckIn = [[CheckInViewController alloc] initWithNibName:#"CheckinViewController" bundle:nil];
UINavigationController* navController4 = [[UINavigationController alloc]
initWithRootViewController:viewControllerCheckIn];
UIViewController *viewControllerProfile = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navController5 = [[UINavigationController alloc]
initWithRootViewController:viewControllerProfile];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, navController3, navController4, navController5, nil];
[self.view addSubview:self.tabBarController.view];
Answer 2:
self.tabBarController.selectedIndex = 2;
Best regards
Okan Sahin