How to bring iOS rootviewcontroller to the foreground - ios7

I'm calling a method in AppDelegate from a modal view to switch to rootviewcontroller (TabBarController) after an event occurs. How can I bring the rootview to the foreground? I shouldn't create a new instance of rootviewcontroller.

You can access the instance of the applications rootViewController using self.window.rootViewController

Related

iOS 7 NavigationController Segue Crash

I have a NavigationController as Initial View and a ViewController as the root view. From that root view i am trying to do a segue with:
[self.navigationController performSegueWithIdentifier:#"Segue" sender:self];
There´s another view controller in my storyboard and i gave the segue the correct identifier. On iOS 8 it works perfect, but on iOS 7 it crashes with the following message:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'Segue'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
I don´t get why it´s not working on iOS 7...
UPDATE: Here´s my Storyboard:
The problem is, that your segue has the UINavigationController as its source.
A UINavigationController should not perform a segue. It should only be connected to a rootViewController, which may be a UIViewController (or its subclass). A segue should be performed from the rootViewController of the UINavigationController. The segue should have the rootViewController as its source and some other UIViewController (or its subclass) as its destination.
Your screenshot shows that your UINavigationController is connected to a rootViewController. You now need to set the rootViewController as the source of the segue (having identifier Segue), which currently has your UINavigationController as its source. Now, from the rootViewController, call
[self performSegueWithIndentifier:#"Segue" sender:nil]
Do this:
[self performSegueWithIdentifier:#"Segue" sender:self];
use Self if you are already performing segue from within the rootViewController.
If not then try this .
[self.navigationController.viewControllers[0] performSegueWithIdentifier:#"Segue" sender:nil];
Hope this will help you.
I think you have no segue in storyboard from rootViewController to other viewController with name #"Segue".

How to open a modal with a navigation bar?

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.

How to get current viewController class name?

but the problem is that my app has both UInavigationController and UITabBarController
so calling navigaionController.topViewController tells me that i have UItabBarController
and
self.window.rootViewController returns UINavigationController
thank's a lot
You can check for the kind of class it is using
[VC isKindOfClass:(myVCClass class)]
The tabbarcontroller is designed to be the top/root viewcontroller of your application. From the documentation:
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
Have the navigationcontroller inside the tabs and have the other view controllers inside the navigationcontrollers on the tabs.
view.class returns a class name as a string:
NSLog (#"Class:%#", view.class);

How to create a UISplitViewController without UIPopoverController?

I need to create a UISplitViewController without a UIpopoverController? How to display both the RootViewController and DetailViewController to be displayed in Portrait mode?
actually, there's a split view controller delegate method called
-(BOOL)splitViewController:shouldHideViewController:inOrientation;
you can just return no for all the orientations so that the root view controller won't go away

ios sdk only one view changes at a time bug

I'm pushing a number of views:
the top one is a UITabBarController
the second one is a UINavigationController with a pushed view
the third one is a modal box.
Once the close button in the modalbox is pressed I'm trying to revert everything to the default state and change the tabbar index.
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:NO];
[self.tabBarController setSelectedIndex:3];
This dismisses the modal view but doesn't do anything else. Any ideas what could be wrong? I read something about a possible ios bug but I don't know how to work around it.
Neither UITabBarController nor UINavigationController is a view. Both are subclasses of UIViewController and have a property NSArray *viewControllers.
If you have an actualView controlled by an ActualViewController that is pushed on top of a rootView controlled by a RootViewController that is the rootViewController for the navigationController, and you also have a modalView controlled by a ModalViewController, then put
[self dismissModalViewControllerAnimated:YES];
in ModalViewController.m, and put
[self.navigationController popViewControllerAnimated:NO];
in ActualViewController.m (from whence modalView is pushed, presumably), and put
[self.tabBarController setSelectedIndex:3];
in RootViewController.m (from whence actualView is pushed, presumably).
If modalViewController was never added to the navigationController, then it doesn't know that the navigationController exists.
If actualViewController was never added to the tabBarController, then it doesn't know that the tabBarController exists.
The easy (and dirty) way:
Dismiss the modal view in the modal view. Make the navigation view controller the delegate of the modal view. Make the tabbar controller the delegate of the navigation controller. When the button is pressed call a method in the navigation controller that pops the view and calls a method of the tabbar controller which changes the selected tab.