How to open a modal with a navigation bar? - objective-c

I am developing an iOS app using Rubymotion.
I am opening a modal and in this modal I want to use a viewcontroller but also a navigation controller which should be the rootViewController (right?).
Is the controller or the navigation controller rootview here?
This is my code:
controller = DetailsController.alloc.init
appsNavController = UINavigationController.alloc.initWithRootViewController(controller)
self.presentModalViewController(appsNavController, animated:true)
I get this message, donĀ“t know if it is related
Application windows are expected to have a root view controller at the end of application launch
I have a rootview controller in the app delegate
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
window.makeKeyAndVisible
window.rootViewController = tabBarController

The problem is you are calling window.makeKeyAndVisible
when there is no rootviewcontroller.
Interchange the lines
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
window.rootViewController = tabBarController
window.makeKeyAndVisible
This may help.
And make sure you have allocated tabBarController with valid viewControllers.

Related

Navigation Controller. Navigation between multiple view controllers

![This is My view controller connection looks][1]
http://i58.tinypic.com/2mepfv4.png
![I have to go from view controller A to VC-B through programatically, Because it should satisfy login authentication based on device ID. Let me Explain Clearly. When user installs my app he should set up his email and verify.After verification He should move to VC-B.After moving VC-B, Viewcontroller-A should not open again when he opens app again. Something like kill View controller-A, and load VC-B whenever he opens app.
Question1- How to kill View controller-A completly.
Second thing i do not want to show navigation bar On View controller-A, But on View VC-B,VC-C and VC-D so on. i want to show navigation bar because user should be able to move back and forth.That's the reason i added navigation controller before VC-B again.
If i'm not able to show Navigation bar on VC-B until i enable show navigation bar on Navigation controller before View Controller A.
Question2-How to enable Navigation bar on VC-B but not on Viewcontroller-A.
][1]
This is the code how am i moving from View controller A to VC-B.
if (alertView.tag == 99) {
if(buttonIndex == 0){
VC-B *vcb =
[self.storyboard instantiateViewControllerWithIdentifier:#"VC-B"];
[self.navigationController pushViewController:vcb animated:YES];
}
}
Help me to point Right direction.
You do not necessarily need to kill the A view controller, I do not think this is a good idea.
You can solve the issue by setting the info in NSUserDefaults when the user is successfully verified. Then navigate to the B view controller.
In the method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
always check if that verified flag was set in NSUserDefaults, and if YES - set the rootViewController of the navigation controller to the B view controller, otherwise to the A view controller.
To hide/unhide the Nav Bar, you can do it from any view controller (assuming they belong to a navigation controller), using this code:
self.navigationController.navigationBar.hidden = YES; // or NO
This code can be written in the view controller classes, inside viewDidLoad, viewWillAppear:, viewDidAppear:, or anywhere you need.
There are also some methods if you want a nice animation for hiding/unhiding.

How to create a splash page for a split view controller

(Xcode6-beta3, Swift, iPad, iOS8)
How can I create a splash page for an iPad app using a split view controller?
I've tried the straight-forward approach of drag n' dropping the little arrow to a new view controller, and setting up a button to segue to the split view controller on a touch up inside. This throws a memory error
I've also tried simply commenting out the following code from the application function in the AppDelegate, but I'm getting a
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [identifier length] > 0'
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
// let splitViewController = self.window!.rootViewController as UISplitViewController
// let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
// splitViewController.delegate = navigationController.topViewController as DetailViewController
return true
}
I've even disconnect the Master-Detail view in Storyboard, so that all that should be loaded is the splash page alone, but it still crashes.
I am so stuck! Thanks for your help.
The problem you were having is related to the code in application:didFinishLaunchingWithOptions:
In that code the template access the "first" view controller defined in the Storyboard to get to the split view controller and set its delegate property. If you change the "little arrow" you are changing UIWindow's rootViewController property, and being of a different view controller, it crashes.
To solve that, the best way is:
create the storyboard as described (normal ViewController with a segue to the original Split VC)
comment out code in application:didFinishLaunchingWithOptions
create a UIView controller subclass for your newly added Scene
in that class, before the segue is done, insert this modified version of the code to set the Split View Controller's delegate property:
let splitViewController = segue.destinationViewController as UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
splitViewController.delegate = navigationController.topViewController as DetailViewController
Working project here

Detect rootcontroller in iphone sdk

I have using two types of controller in my application i.e. NavigationController and presentViewController.
How can I detect base controller at any instance through code i.e I am using navigation or presentviewcontroller to transist one viewcontroller to another viewcontroller?
Try this for take rootviewcontroller of navigation:
UIViewController *topViewController = [self.navigationController topViewController];
for present modal view controller check out the 'presentingViewController' property of UIViewController and for navigation you can get the array of view controllers NSArray *ArryViewControllers=[self.navigationController viewControllers]; and then get the object at index 0 . this will be the root view controller of that navigation controller.

Objective c : UINavigationViewController unable to load root controller

Hello I have a navigation view controller on the Interface builder and have it placed on a window.rootviewcontroller and then I pushed the initialized view controller to it. I used this line here: [window.rootViewController addSubViews:[navigation view]];
The [navigation view] has no view inside.
But if i create a navigation in code and do the same as before, i can have the navigation appears on the screen.
Does anyone know what is wrong? i have linked the navigation with the Interface Builder as well.
Have you set the class correctly for the "viewcontroller" which is visible inside navigationcontroller(in XIB) within the navigationController hierarchy
You should try this
if you want to set RootViewController
self.window.rootViewController = navigationController;
//navigationController its is rOotViewControler.
if You want to add as SubView.
[self.window addSubview:navigationController.view];
i hope it'll help you.

How to remove/hide tabbar in tabbarconmtroller app?

In my tabbarcontroller application having four bars, each tabbar having navigationcontroller inside viewcontroller. How should i hide for particular tabbar for particular tab in landscape orientation?.
To hide the TabBar when you push a new viewController to the navigation stack, simply add this code to the init method of that viewController:
self.hidesBottomBarWhenPushed = YES;