How to achieve SplitView Functionality in Portrait mode in iOS? - ios

I'm trying to implement SplitView functionality in my iOS application, it's working fine only in landscape mode in iPad devices.
If I launch or rotate the application from landscape to portrait mode splitView functionality is collapsing.
How to achieve SplitView functionality in iPhone(portrait and landscape) and iPad(Portrait mode) devices?
Please find my codeenter image description here below code.
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *masterViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:#"DetailViewController"
bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[CustomSplitViewController alloc]initWithNibName:#"CustomSplitViewController" bundle:nil];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
TabBarDetailController *secondVC = [[TabBarDetailController alloc]initWithNibName:#"TabBarDetailController" bundle:nil];
secondVC.tabBarItem.title = #"Second";
ThirdViewController *thirdVC = [[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
thirdVC.tabBarItem.title = #"Third";
FourthViewController *fourthVC = [[FourthViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
fourthVC.tabBarItem.title = #"Fourth";
MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:#"MoreViewController" bundle:nil];
moreVC.tabBarItem.title = #"More";
//make an array containing view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:self.splitViewController,secondVC,thirdVC,fourthVC,moreVC,nil];
[tabBarController setViewControllers:viewControllers];
self.splitViewController.tabBarItem.title = #"HOME";
[self.window addSubview:tabBarController.view];
self.window.rootViewController=tabBarController;
[[self window] makeKeyAndVisible];
return YES;
}
Thanks in advance.

Related

MMDrawerController with UITabBarController showing a black gap on top of the center view

I am opening a UITabBarController with MMDrawerController on the left side.
So from my delegate didFinishLaunchingWithOptions I am making a MMDrawerController with centerNav is a TabBarController and leftNav is a ViewController with Navigation controller. So as expected the tabbar is coming with the mmdrawer but there is a black gap on top of the LandingTabBarController.If I open the LandingTabBarController directly then it is coming from the top. Whats going wrong?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LandingTabBarController *landingTabBarController = [[LandingTabBarController alloc]initWithManagedObjectContext:self.managedObjectContext];
UIViewController * drawerNavController = [storyboard instantiateViewControllerWithIdentifier:#"DrawerViewController"];
UINavigationController *centerNav = [[UINavigationController alloc]initWithRootViewController:landingTabBarController];
UINavigationController *leftNav = [[UINavigationController alloc]initWithRootViewController:drawerNavController];
centerNav.navigationBar.barStyle = UIStatusBarStyleLightContent;
leftNav.navigationBar.barStyle = UIStatusBarStyleLightContent;
_drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController:leftNav];
_drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
_drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningCenterView;
_drawerController.showsShadow = NO;
//[_drawerController setDrawerVisualStateBlock:[MMDrawerVisualState slideVisualStateBlock]];
[_drawerController setDrawerVisualStateBlock:MMDrawerSideNone];
self.window.rootViewController = _drawerController;
[self.window makeKeyAndVisible];
return YES;
}
This is my LandingTabBarController viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
UIViewController *firstViewController = [[UIViewController alloc]init];
[firstViewController.view setBackgroundColor:[UIColor redColor]];
UIViewController *secondViewController = [[UIViewController alloc]init];
[secondViewController.view setBackgroundColor:[UIColor greenColor]];
[tabViewControllers addObject:firstViewController];
[tabViewControllers addObject:secondViewController];
[self setViewControllers:tabViewControllers];
firstViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"one" image:[UIImage imageNamed:#"icon_feed"] tag:1];
secondViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"two" image:[UIImage imageNamed:#"icon_apps"] tag:2];
}
Screenshot of the debugger

IIViewDeckController is not working when push by navigation controller

Please help me in my project. I am using IIViewDeckController but its not working when pushed by view controller
Heres the hierarchy:
ViewController (Push)----> IIViewDeckController (with Left and centerview).
Here is my code when initialising the IIViewDeckController:
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
self.profileView = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navC = [[UINavigationController alloc] initWithRootViewController:self.profileView];
IIViewDeckController *deckView = [[IIViewDeckController alloc] initWithCenterViewController:navC leftViewController:self.navigationView rightViewController:nil];
deckView.leftSize = 50;
[deckView disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return deckView;
}
then this is my code when I'm pushing IIViewDeckController using another ViewController
- (IBAction)signInAction:(id)sender {
IIViewDeckController *deckView = [[UIManager sharedItems] generateControllerStack];
[self.navigationController pushViewController:deckView animated:YES];
}
Thanks you very much guys :)
when I clicked sign in which is I will push my iiviewdeckcontroller with left and centre view this appears
Did you created it like this?
I am using it as root view controller. and it is working fine
UINavigationController* navController=(UINavigationController*)[[UIStoryboard storyboardWithName:#"Main" bundle: nil] instantiateViewControllerWithIdentifier:#"HomeViewController"];
SlideMenuViewController* slide=[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SlideMenuViewController"]; /
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:navController
leftViewController:slide
rightViewController:nil
topViewController:nil
bottomViewController:nil];
float leftSize=self.window.frame.size.width - (88*self.window.frame.size.width)/320;
deckController.panningMode = IIViewDeckFullViewPanning;
deckController.leftSize =leftSize;
You can do like that.
//Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController"
bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
import IIViewDeckController.h in ViewController.h then
- (IBAction)GoToNext:(id)sender
{
IIViewDeckController *objIIVC = [self.storyboard instantiateViewControllerWithIdentifier:#"Your VC's Identifier"];
[self.navigationController pushViewController:objIIVC animated:YES];
}
Here is my code
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
UIViewController *centerController = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
self.viewDeck = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:self.navigationView rightViewController:nil topViewController:nil bottomViewController:nil];
self.viewDeck.leftSize = 50;
[self.viewDeck disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return self.viewDeck;
}

Show UITabBar without beeing RootViewController

I'm having an LoginViewController which is the RootViewController. This ViewController should not have the TabBar included. The Rest of the ViewController should contain the UITabBar, But it is not showing. If i make the tabBar the rootController it will show the tabBar in the viewcontrollers. This would also make the firsttab the rootviewcontroller which it should not.
My question is then how can i make the loginview the rootViewController without an tabBar and still show the tabBar in the other viewcontrollers?
My code:
tabBarController = [[UITabBarController alloc] init];
MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab];
FixtureViewController *secondTab = [[FixtureViewController alloc] initWithNibName:#"FixtureViewController" bundle:nil];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondTab];
WorldCupViewController *thirdTab = [[WorldCupViewController alloc] initWithNibName:#"WorldCupViewController" bundle:nil];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdTab];
LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:loginView];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navController, navController2, navController3];
navController.tabBarItem.image = [UIImage imageNamed:#"message-7"];
navController2.tabBarItem.image = [UIImage imageNamed:#"football-32"];
navController3.tabBarItem.image = [UIImage imageNamed:#"trophy-32"];
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:110/255.0f green:89/255.0f blue:196/255.0f alpha:1.0f]];
[self.window setRootViewController:navController4];
[self.window makeKeyAndVisible];
What you need to do is transition the application from the LoginViewController to the Tabbar. What I would suggest doing is replacing the LoginViewController with the TabBar as the rootViewController.
Here is some sample code, perform this action in your AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:loginView];
[self.window setRootViewController:navController4];
[self.window makeKeyAndVisible];
return YES;
}
-(void)transitionToTabBar
{
// Set the TabBar how you are in your sample code, this is just an example.
[self.window setRootViewController:[[UITabBarController alloc] initWithNibName:#"SomeNib" bundle:Nil]];
[UIView transitionWithView:self.window duration:0.5f options:UIViewAnimationOptionTransitionCurlDown animations:^{
[self.window makeKeyAndVisible];
} completion:nil];
}
You should use main View controller (for MenuViewController) and by using segue you can present another view controller which has TabBar in it.

PushView on PresentViewController iOS

I want to Push my viewController on PresentViewController
When i click on button initially i am loading PresentViewController, here is my code.
- (IBAction)JoinClicked:(id)sender{
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.view.window.rootViewController presentViewController:detail_view_controller
animated:YES
completion:NULL];
}
this works fine, but when i click on button which is there on PresentViewController on click i want to Push my view, but in does not pushes.
Please help, Thanks in advance.
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];
Try like this to push viewController. If you use TabBar do like this in AppDelegate. If you create TabBar Drag and drop means leave that. Create TabBar Programatically like below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabController = [[UITabBarController alloc]init];
self.viewController = [[CalculatorViewController alloc] initWithNibName:#"CalculatorViewController" bundle:nil];
UITabBarItem *tab_item1 = [[UITabBarItem alloc]init];
//tab_item1.title = #"Calculator";
tab_item1.image = [UIImage imageNamed:#"Calculator.png"];
[self.viewController setTabBarItem:tab_item1];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:self.viewController];
ShowPhoneViewController *phone = [[ShowPhoneViewController alloc]init];
UITabBarItem *tab_item2 = [[UITabBarItem alloc]init];
tab_item2.title = #"Latest Mobiles";
tab_item2.image = [UIImage imageNamed:#"Mobile.png"];
[phone setTabBarItem:tab_item2];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:phone];
CurrencyConvertorViewController *currency = [[CurrencyConvertorViewController alloc]init];
UITabBarItem *tab_item3 = [[UITabBarItem alloc]init];
tab_item3.title = #"Units Convertor";
tab_item3.image = [UIImage imageNamed:#"Dollar.png"];
[currency setTabBarItem:tab_item3];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:currency];
SettingsPageViewController *setting = [[SettingsPageViewController alloc]init];
UITabBarItem *tab_item4 = [[UITabBarItem alloc]init];
tab_item4.title = #"Settings";
tab_item4.image = [UIImage imageNamed:#"Settings.png"];
[setting setTabBarItem:tab_item4];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:setting];
tabController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
I hope you got now
pushviewcontroller is the feature of UINavigationController where you can push one viewcontroller on another vierw controller. Here you are using a single viewcontroller as a rootviewcontroller so either you must change your rootviewcontroller to UINavigationcontroller or you can use "addSubview method" to add new viewController on the current viewcontroller.
but the better option is to add uinavigationcontroller as a rootviewcontroller.
AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *first = [[FirstViewController alloc]
initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navController =[[UINavigationController alloc]
initWithRootViewController:first];
[self.window setRootViewController:navController];
}
Now when as you want to switch from FirstViewController to SecondViewController on button clicked than you have to use pushviewcontroller
FirstViewController.h
-(void) nextBtnPressed {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:second animated:TRUE];
}

How can we implement a common tabbar for all views in IOS?

I am new to IOS. In my app's home, there are 3 tabs and 4 buttons(using navigation controllers). I created a tabbarcontroller inside appdelegate.m as follows:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//Initializing the view controllers
UIViewController *disController1 = [[DisController1 alloc]initWithNibName:#"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:#"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:#"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:#"DisController2" bundle:nil];
NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:disController1];
[viewControllersArray addObject:viewController];
[viewControllersArray addObject:wishlistController];
[viewControllersArray addObject:helpController];
[viewControllersArray addObject:disController2];
//Initializing the tab bar controller
UIImage *img = [UIImage imageNamed:#"SES_tab bar"];
CGSize newSize = CGSizeMake(SCRN_WIDTH, TABHEIGHT);
Common *common = [[Common alloc]init];
UIImage *newImage = [common imageResize:img andResizeTo:newSize];
[common setTabBarColorandImage:newImage];
tabController = [[UITabBarController alloc]init];
tabController.viewControllers = [NSArray arrayWithObjects:disController1, viewController,wishlistController,helpController,disController2 ,nil];
tabController.selectedIndex = 1;
UITabBarItem *firstTab = [[tabController.tabBar items]objectAtIndex:0];
UITabBarItem *lastTab = [[tabController.tabBar items]objectAtIndex:4];
[firstTab setEnabled:NO];
[lastTab setEnabled:NO];
UINavigationController *navCtrl = [[UINavigationController alloc]initWithRootViewController:tabController];
//navCtrl.navigationBarHidden = NO;
//[navCtrl.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
[navCtrl.navigationBar setBarStyle:UIBarStyleBlackTranslucent ];
[navCtrl.navigationBar.topItem setTitle:#"Home"];
[self.window addSubview:tabController.view];
self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
return YES;
TabBar works fine for my home page.But my problem is when i clicks on a button, Tab bar doesn't appear in the new view. How can I implement that?
You should create UINavigationControllers for each of your tabs. Set each view controller in your current array as the root view controller of each of those navigation controllers.
EDIT:
UIViewController *disController1 = [[DisController1 alloc]initWithNibName:#"DisController1" bundle:nil];
UIViewController *viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UIViewController *wishlistController = [[Wishlist alloc]initWithNibName:#"Wishlist" bundle:nil];
UIViewController *helpController = [[HelpController alloc]initWithNibName:#"HelpController" bundle:nil];
UIViewController *disController2 = [[DisController1 alloc]initWithNibName:#"DisController2" bundle:nil];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:disController1];
//etc. for each of the view controllers that you have allocated.
NSMutableArray *viewControllersArray = [[NSMutableArray alloc]init];
[viewControllersArray addObject:navController1];
[viewControllersArray addObject:navController2];
[viewControllersArray addObject:navController3];
[viewControllersArray addObject:navController4];
[viewControllersArray addObject:navController5];

Resources