How can i add UIViewController after splash screen in phonegap project? - ios

i have created one phonegap ios project.In that currently after splash screen it loading a index.html file. I like to add one introduction viewcontroller like below image after splash screen and user have an option to close introduction viewcontroller so they can see the index.html file.
Is there anyway to add UIViewController file before loading index.html ??
eg: SPLASH SCREEN --> INTRODUCTION VIEWCONTROLLER --> INDEX.html

Go to Classes >> AppDelegate.m file replace didFinishLaunchingWithOptions function with this code
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.autoresizesSubviews = YES;
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES;
UIViewController *myController = [[UIViewController alloc] init];
UIView *myView = [[UIView alloc] initWithFrame:self.viewController.view.frame];
myView.backgroundColor = [UIColor whiteColor];
myController.view = myView;
UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController:myController];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel"
style:UIBarButtonItemStyleDone target:self action:#selector(cancel)];
myController.navigationItem.leftBarButtonItem = leftButton;
self.window.rootViewController = myNav;
[self.window makeKeyAndVisible];
return YES;
}
-(void)cancel{
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
}

Related

How to set rootViewController for navigation view controller and tabbar controller in AppDelegate

i have this problem. When i set rootViewController for TabbarController, it show correctly. But i set another rootViewController for navigation bar, TabbarController will not able to display. Any idea?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[DCTabBarController alloc] init];
DCTabBarController *tabBar = (DCTabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:2];
Map_ViewController *vc = [[Map_ViewController alloc] init];
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:vc];
[rootNav.navigationBar setBackgroundImage:[UIImage imageNamed:#"navbarBackImage"] forBarMetrics:UIBarMetricsDefault];
rootNav.navigationBar.tintColor = [UIColor whiteColor];
[rootNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];
LeftViewController *leftVC = [[LeftViewController alloc] init];
RightViewController *rightVC = [[RightViewController alloc] init];
XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:rootNav];
slideMenu.leftViewController = leftVC;
slideMenu.rightViewController = rightVC;
self.window.rootViewController = slideMenu;
[self.window makeKeyAndVisible];
return YES;
}
After applied Adeel solution, here is the output.But items in tabbar will not display accordingly.
One important thing to mention here is that an application's window can have only one rootViewController (of course). Like I said in my comment as well, you probably want to do something like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Map_ViewController *vc = [[Map_ViewController alloc] init];
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:vc];
[rootNav.navigationBar setBackgroundImage:[UIImage imageNamed:#"navbarBackImage"] forBarMetrics:UIBarMetricsDefault];
rootNav.navigationBar.tintColor = [UIColor whiteColor];
[rootNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil]];
DCTabBarController *tabBar = [[DCTabBarController alloc] init];
[tabBar setViewControllers:#[rootNav]];
self.window.rootViewController = tabBar;
LeftViewController *leftVC = [[LeftViewController alloc] init];
RightViewController *rightVC = [[RightViewController alloc] init];
XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:tabBar];
slideMenu.leftViewController = leftVC;
slideMenu.rightViewController = rightVC;
self.window.rootViewController = slideMenu;
[self.window makeKeyAndVisible];
return YES;
}

MMDrawerController configure left menu

My Left menu displace center view. It looks worse than if Left Menu cover center view.
explanation
How i can configure it?
//MMDrawerController
ViewController * centerViewController = [[ViewController alloc] init];
UINavigationController *centerNavigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
ViewController *leftViewController = [[ViewController alloc] init];
UINavigationController *leftNavigationController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
_drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNavigationController leftDrawerViewController:leftNavigationController];
[leftNavigationController setNavigationBarHidden:YES];
[centerNavigationController setNavigationBarHidden:YES];
[_drawerController setMaximumLeftDrawerWidth:300.0];
[_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
green:173.0/255.0
blue:234.0/255.0
alpha:1.0];
[self.window setTintColor:tintColor];
[self.window setRootViewController:_drawerController];
[self.window makeKeyAndVisible];

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.

UINavigationController not displaying

I am new to IOS dev so I'm sure the answer is simple but my ignorance makes it hard to find the answers online. I'm trying to use a UINavigationController to switch between views. Thus far I have been succesfully displaying the first view with the following code.
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.window.rootViewController = control;
I then wrote the code to add the navigation controller but when I run it I see mostly a black screen with a gray bar at the top of it. Here's the code
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
_navController = [[UINavigationController alloc] initWithRootViewController:control];
self.window.rootViewController = _navController;
Here is the complete code for AppDelegate.m in 'didFinishLaunchingWithOptions':
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController: control];
[self.navController setNavigationBarHidden:YES];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
Interestingly, the gray bar near the top is slightly translucent and I can see some of my UI elements underneath it.
EDIT: I removed the top bar and now I see the following!
This is what should be seen.
I have added navigation bar setup for your convenience. Try this in your AppDelegate.m under didFinishLaunchingWithOptions: method -
FLInitialMapViewController * control = [FLInitialMapViewController new];
UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController: control];
self.window.rootViewController = myNav;
// Setup navigation bar programmatically
UINavigationBar *navigationBar = myNav.navigationBar;
navigationBar.barTintColor = [UIColor orangeColor];
navigationBar.barStyle = UIBarStyleBlackOpaque;
// Boiler plate code from AppDelegate
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

ios splitviewcontroller landscape fail

I have spliteview project and forced it in landscape mode.
It works fine before I upgrade my iOS SDK to iOS6.
But after upgrade, when I use iOS 5.1 Simulator to run, it always show in portrait mode and Master view is gone.
and here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
CustomverDetailViewController *custView = [[[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, custView];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
Any ideas?
I try to give different code for different version, in iOS6 it seems ok, but in iOS5.1 still will changing orientation while I enter this view, I guess when I alloc an new UIWindow , it orginial orientation is portrait.
here I changed my code:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
left = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:left] autorelease];
right = [[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, right];
if (([[[UIDevice currentDevice] systemVersion] floatValue ] < 6.0 )) {
self.splitViewController.delegate = left;
[self.splitViewController.view setFrame:CGRectMake(0, 0, 1024.0f, 768.0f)];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}else{
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
[right release];
Try to add new delegate method added in iOS 6
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)shouldAutorotate {
return NO;
}

Resources