UISplitViewController does not show my DetailViewController - ios

I have used UISplitViewController on Storyboard, i have set UINavigationController both for master and detail viewcontroller. Master ViewController is loaded, but Detail ViewController does not load.
I could not figure out what might be wrong?
Could you please help me?
My code on AppDelegate is as follows;
if([Utils isIpad])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:[NSBundle mainBundle]];
UISplitViewController *splitViewController = [storyboard instantiateViewControllerWithIdentifier:#"splitViewController"];
//UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"navigationViewControllerMaster"];
splitViewController.delegate = (id)navigationController.topViewController;
[self.window setRootViewController:navigationController];
}

Related

Starting navigation controller from appDelegate

Can anyone tell me how to start UINavigationContoller from ÀppDelegate?
I can start arootViewContollerbut cannot start a specificUIViewControllerlike I was trying in commented code.
The commented code starts the **ChooseTableViewController** but does not displayUINavigationBar`.
whats the better approach?
Here is my code
- (void)setRootViewController:(NSString *)storyBoardName {
//set the Root ViewController
UIStoryboard *story = [UIStoryboard storyboardWithName:storyBoardName
bundle:nil];
UINavigationController *newViewController =
[story instantiateInitialViewController];
self.window.rootViewController = newViewController;
/*
ChooseTableViewController *chooseTableViewController =
[story instantiateViewControllerWithIdentifier:#"ChooseTableViewController"];
self.window.rootViewController = chooseTableViewController;
*/
}
Appdelegate.h
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *navigationController;
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.navigationController = [storyboard instantiateViewControllerWithIdentifier:#"navigation"];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"ChooseTableViewController"];
navigationController=[[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController =self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
// Your main storyboard
UIStoryboard *story = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
// Your root navigation controller
UINavigationController *newViewController = [story instantiateInitialViewController];
// Your root view controller for root navigation controller
ChooseTableViewController *chooseTableViewController = [story instantiateViewControllerWithIdentifier:#"ChooseTableViewController"];
// Set your view controller as root view controller of your root navigation controller
newViewController.rootViewController = chooseTableViewController;
// set your root navigation controller
self.window.rootViewController = newViewController;

Three time ViewDidload method is calling

I am using Two storyboard one Main and another Dashboard.
After successfull response, I am loading LGSideMenu
Issue is DashboardViewController ViewDidLoad is calling 3 times.
-(void)loadDashboardController{
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Dashboard" bundle:nil];
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"NavigationController"];
DashboardViewController *mainViewController = [storyboard instantiateInitialViewController];
mainViewController.rootViewController = navigationController;
[mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:0];
UIWindow *window = [UIApplication sharedApplication].delegate.window;
window.rootViewController = mainViewController;
[UIView transitionWithView:window
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:nil
completion:nil];
});
}
Is any one face this kind of issue?
you should set rootviewcontroller only once on window of your application. that's it. other view controller should be pushed on it or you should set as viewocontrollers of your navigation controller. so only set,
window.rootViewController = mainViewController;
//or
window.rootViewController = navigationcontroller;

How to pass property to root view controller while presenting UINavigationController?

I'm doing in-app browser to open links w-out using safari from any viewController in app.
This is a code for launching browser with link in AppDelegate.m
-(void)openExternalRef:(NSString *)ref
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
CSDBrowser* browser = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowser"];
browser.urlString = ref;
browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.window makeKeyAndVisible];
UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowserNavi"];
[self.window.rootViewController presentViewController:navi animated:YES completion:nil];
[self.window.rootViewController.navigationController pushViewController:browser animated:YES];
}
i need to pass a variable "ref" to my viewcontroller, but i need to launch navigation controller first, any ideas?
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
[self.window makeKeyAndVisible];
UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowserNavi"];
CSDBrowser* browser = [navi viewControllers][0];
browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
browser.urlString = ref;
[self.window.rootViewController presentViewController:navi animated:YES completion:nil];

How to navigate the navigationcontroller rootviewcontrollr subview controller

in my application i mentioned the tab bar controller with 2 tabs tab1 and tab2.And each tab having the navigation view controller with root view controllers.And my scenario is like below
tab1 -> viewcontroller1 (navigationcontroller rootviewcontroller) -> viewcontroller2.
So now i want to move directly from app delegate to view controller2.How is it possible.
I did this one like this in app delegate. But it's moving to viewcontroller1.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
self.tabbarController = [mainStoryboard instantiateViewControllerWithIdentifier:#"tabbarcontroller"];
[self.tabbarController setSelectedIndex:1];
viewcontroller2 *view =(viewcontroller2 *) [mainStoryboard instantiateViewControllerWithIdentifier:#"view2"];
[self.tabbarController.navigationController pushViewController:view animated:YES];
self.window.rootViewController=self.tabbarController;
Tab1 -> Viewcontroller1(navigationcontroller rootviewcontroller) -> Viewcontroller2
I have used this approach some times
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
self.tabbarController = [mainStoryboard instantiateViewControllerWithIdentifier:#"tabbarcontroller"];
[self.tabbarController setSelectedIndex:1];
viewcontroller1 *view1 =(viewcontroller1 *) [mainStoryboard instantiateViewContro1llerWithIdentifier:#"view1"];
viewcontroller2 *view2 =(viewcontroller2 *) [mainStoryboard instantiateViewControllerWithIdentifier:#"view2"];
[self.tabbarController.navigationController pushViewController:view1 animated:NO];
[self.tabbarController.navigationController pushViewController:view2 animated:YES];
self.window.rootViewController=self.tabbarController;

How to add navigation controller programmatically?

I use code below, but it is not loaded:
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.mapViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self];
self.navigationBar = [[UINavigationBar alloc]init];
[self.view addSubview:self.navigationBar];
[self.navigationController.navigationController pushViewController:self.mapViewController animated:YES];
try as below
UIViewController *bbp=[[UIViewController alloc]initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[self.navigationController pushViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
Add this code to your AppDelegate.m in the didFinishLaunchingWithOptions function:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME" bundle:nil];
yourViewControllerClassName *vc = [sb instantiateViewControllerWithIdentifier:#"YOUR_VIEWCONTROLLER_ID"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
yourViewControllerClassName is the .h and .m file name that is linked to your viewController.
YOUR_STORYBOARD_NAME is the name of your .storyboard file. For example, fill in Main if your .storyboard file is called Main.storyboard.
YOUR_VIEWCONTROLLER_ID is the ID for your veiwController. You can edit it in the Identity inspector.(See photo)
Hope this helps:)

Resources