created Tab bar and side menu Issues - ios

I created tab bar and side menu using Sw reveal programmatically but after implementing all process i cant able to view side menu and my tab bar also disappeared...i don't know how to alloc them pleas help me out
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.tabBarController =[[UITabBarController alloc]init];
//Initialize View controller and speciality
UIViewController *viewcontroller1=[[HomeView alloc]init];
UIViewController *viewcontroller2=[[Speciality alloc]init];
UIViewController *viewcontroller3=[[Activity alloc]init];
UIViewController *viewcontroller4 =[[Notification alloc]init];
UIViewController *viewcontroller5 =[[Profile alloc]init];
self.tabBarController.viewControllers=[NSArray arrayWithObjects:viewcontroller1,viewcontroller2,viewcontroller3,viewcontroller4,viewcontroller5, nil];
self.window.rootViewController =self.tabBarController;
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000];
self.window.backgroundColor = [UIColor whiteColor];
HomeView *frontViewController = [[HomeView alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

You set your window.rootViewController two times. And it seems the second time you assign nil to it, as I can't see any initialization/assignement to self.viewController.

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

App delegate issues with multiple view controllers

I created tab bar controller and implemented in app delegate but before that i also implemented other view controller.i don't know how to use call them orderly.please tell me how to make them arrange as i like.
#interface AppDelegate ()
{
UINavigationController *navigation;
}
#property (strong, nonatomic) JASidePanelController *viewController;
#property (strong, nonatomic) UITabBarController *this;
#end
#implementation AppDelegate
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
navigation = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
self.window.rootViewController = navigation;
//UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.window = window;
self.viewController = [[JASidePanelController alloc] init];
self.viewController.shouldDelegateAutorotateToVisiblePanel = NO;
self.viewController.leftPanel = [[LeftViewController alloc] init];
UIViewController *viewcontroller1=[[HomeView alloc]init];
UIViewController *viewcontroller2=[[Speciality alloc]init];
UIViewController *viewcontroller3=[[Activity alloc]init];
UIViewController *viewcontroller4 =[[Notification alloc]init];
UIViewController *viewcontroller5 =[[Profile alloc]init];
viewcontroller1.view.backgroundColor = [UIColor whiteColor];
viewcontroller2.view.backgroundColor = [UIColor whiteColor];
viewcontroller3.view.backgroundColor = [UIColor whiteColor];
viewcontroller4.view.backgroundColor = [UIColor whiteColor];
viewcontroller5.view.backgroundColor = [UIColor whiteColor];
UINavigationController *navcontroller1=[[UINavigationController alloc] initWithRootViewController:viewcontroller1];
UINavigationController *navcontroller2=[[UINavigationController alloc] initWithRootViewController:viewcontroller2];
UINavigationController *navcontroller3=[[UINavigationController alloc] initWithRootViewController:viewcontroller3];
UINavigationController *navcontroller4 =[[UINavigationController alloc] initWithRootViewController:viewcontroller4];
UINavigationController *navcontroller5 =[[UINavigationController alloc] initWithRootViewController:viewcontroller5];
viewcontroller1.title = #"Home";
viewcontroller2.title = #"Speciality";
viewcontroller3.title = #"Activity";
viewcontroller4.title = #"Notification";
viewcontroller5.title = #"Profile";
navcontroller1.tabBarItem.image = [UIImage imageNamed:#"home"];
navcontroller2.tabBarItem.image = [UIImage imageNamed:#"special"];
navcontroller3.tabBarItem.image = [UIImage imageNamed:#"activity"];
navcontroller4.tabBarItem.image = [UIImage imageNamed:#"notify"];
navcontroller5.tabBarItem.image = [UIImage imageNamed:#"Pro"];
self.this = [[UITabBarController alloc] init];
self.this.viewControllers=[NSArray arrayWithObjects:navcontroller1,navcontroller2,navcontroller3,navcontroller4,navcontroller5, nil];
self.this.tabBar.barTintColor = RGBCOLOR(249, 178, 131);
self.viewController.centerPanel = _this;
[self.window makeKeyAndVisible];
return YES;
}
Here, you set the window's root controller to a navigation controller:
self.window.rootViewController = navigation;
And then you go on to instantiate a handful of other nav controllers and add them to a tab controller. It's not clear from your question what you're trying to achieve, but if you want your app to use a tab controller, you'll want to set your window's root controller to the tab controller, not a navigation controller.

How to add TabbarController to NavigationController

I have a project with navigationController and storyboard.
Now i need to add another project to this (combine two projects)
I want to use TabbarController to switch between two navigationControllers.
How can I realise this?
put Down this Code in Your AppDelegates view controller :-
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBar = [[UITabBarController alloc] init];
ViewController *homeVC = [[ViewController alloc] init];
homeVC.tabBarItem.title = #"Home";
homeVC.tabBarItem.image = [UIImage imageNamed:#"Home-icon.png"];
UINavigationController *HomeNavi = [[UINavigationController alloc] initWithRootViewController:homeVC];
settingViewController *settingVC = [[settingViewController alloc] init];
settingVC.tabBarItem.title = #"Setting";
settingVC.tabBarItem.image = [UIImage imageNamed:#"Setting-icon.png"];
UINavigationController *settingNavi = [[UINavigationController alloc] initWithRootViewController:settingVC];
tabBar.viewControllers = [NSArray arrayWithObjects:HomeNavi,settingNavi, nil];
HomeNavi.navigationBarHidden = YES;
settingNavi.navigationBarHidden = YES;
[self.window makeKeyAndVisible];
self.window.rootViewController = tabBar;
// Override point for customization after application launch.
return YES;
}

How to programmatically add a UITabBarController & UINavigationController in AppDelegate?

How to add a UINavigationController & UITabBarController programmatically in app delegate.
Don't forget in the AppDelegate.h file to add:
#property (strong, nonatomic) UITabBarController *tabBarController;
Below is the AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.tabBarController = [[UITabBarController alloc] init];
ViewController1 *VC1 = [[ViewController1 alloc] init];
VC1.title = #"Tab Title Here";
UINavigationController *VC1Navigation = [[UINavigationController alloc]
initWithRootViewController:VC1];
ViewController2 *VC2 = [[ViewController2 alloc] init];
VC2.title = #"Tab Title Here";
UINavigationController *VC2Navigation = [[UINavigationController alloc]
initWithRootViewController:VC2];
ViewController3 *VC3 = [[ViewController3 alloc] init];
homeView.title = #"Tab Title Here";
UINavigationController* VC3Navigation = [[UINavigationController alloc]
initWithRootViewController:VC3];
NSArray* controllers = [NSArray arrayWithObjects:VC1Navigation, VC2Navigation, VC3Navigation, nil];
self.tabBarController.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

MHTabBarController add to uiviewcontroller

Im trying to use the MHTabBarController https://github.com/hollance/MHTabBarController
, in the example the custom view controller is added as a rootViewController in app delegate,
i want to add 3 tabs inside a standard tab bar controller's view for example MainViewController
here is my code inside viewDidLoad in MainViewController.m:
//MHTabBarController config
ListViewController *listViewController1 = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
ListViewController *listViewController2 = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
ListViewController *listViewController3 = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
listViewController1.title = #"Tab 1";
listViewController2.title = #"Tab 2";
listViewController3.title = #"Tab 3";
NSArray *viewControllers = #[listViewController1, listViewController2, listViewController3];
MHTabBarController *tabBarController = [[MHTabBarController alloc] init];
tabBarController.delegate = self;
tabBarController.viewControllers = viewControllers;
[self.view addSubview:tabBarController.view];
ive also added the in MainViewController.h
but its not working, its showing a table but not the tabs on top.
what im missing?
That code should go inside the AppDelegate.m
Something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
MainViewController *mainViewController = [[MainViewController alloc] init];
mainViewController.title = #"Main Tab";
NSArray *viewControllers = #[mainViewController];
MHTabBarController *tabBarController = [[MHTabBarController alloc] init];
tabBarController.delegate = self;
tabBarController.viewControllers = viewControllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
This way you're adding a the tab bar into the MainViewController, if you wanna add the same tab bar into other view controllers, just add the view controllers into the viewControllers array.

Resources