Hullo,
I would like to create a new target for a project without overcrowding the main view controller with #ifdef's. So I am thinking of splitting its functions with a weaker superclass and have the new target use the top one. How do I configure the new target to attach the top view controller to the view controller in the storyboard instead of the bottom one as in the old target?
You would have to invoke and set the view controller manually like so:
UIStoryboard *storyboard = [UIApplication sharedApplication].keyWindow.rootViewController.storyboard;
UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerIdentifier"];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:myViewController animated:YES completion:nil];
Related
I have a swrevealcontroller on my storyboard.I move to different view controller by passing selecting the view controller name in the table view.Now i am also showing a new table view when i tap on one of the item of tableview in swrevealcontroller.In select of new tableview item i want to show a new view controller which will not be part of the swrevealcontroller.But i am not able to show this.
I have tried this code but it does not show the back button when new view controller is shown.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *vc = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:#"DetailController"];
[self presentViewController:vc animated:YES completion:nil];
Thanks in advance.
It's because presentViewController present a viewcontroller as a modal one. Secondly, even if you switch from presentViewController to pushviewcontroller an error will be thrown due to the fact that UINavigationController can not be pushed by another UINavigationController.
I would like to add a storyboard inside existing UIViewController (something like iframe in html)
I have my MainViewController and I'm adding the storyboard view controller as a subview like this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Search" bundle: [NSBundle mainBundle]];
SearchViewController *search = (SearchViewController *)[[sb instantiateViewControllerWithIdentifier:#"SearchViewController"] visibleViewController];
[self addChildViewController:search];
[self.view addSubview:search.view];
Now my search.storyboard have 2 view controllers and they are embedded inside navigation controller.
Now when the search view is loaded the navigation controller is nil.. :\
How can I implement this solution with using the navigation controller? Thx.
My app is designed using a UITabBarController and im trying to present a view on top of that (a login screen) from the app delegate. When i use the following code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
tabBarController = [[UITabBarController alloc] initWithNibName:#"Main_TabBarController" bundle:nil];
self.window.rootViewController = tabBarController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
Login_ViewController *lvc = [storyboard instantiateViewControllerWithIdentifier:#"Login_ViewController"];
[self.window.rootViewController presentViewController:lvc animated:YES completion:nil];
I get the error Warning: Attempt to present <Login_ViewController: 0x716fac0> on <UITabBarController: 0x7165240> whose view is not in the window hierarchy! and the screen is just black. How do i add Login_ViewController to the window hierarchy?
You can always grab the current root viewcontroller and use it to present your login controller.
UIViewController *presentingController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[presentingController presentViewController:viewController animated:YES completion:nil];
In addition, depending on how I want my login screen to look, I will push the login controller using UIModalPresentationFormSheet.
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
You're using two different mechanisms for creating your UI. You should move your tab bar controller into the storyboard. When you instantiate your storyboard, it overwrites your window with a new instance and the first controller as the root controller.
The error message is telling you the tab bar controller's view is not in the view hierarchy, not the other way around.
I would create a controller with a view consisting of just your application logo and inside of this controller determine whether you need to go to the login screen or not (if you have persistent logins). Then from the login screen transition to the tab bar controller.
Unless the storyboard you're loading isn't the main storyboard, you shouldn't need to load it manually. You should be able to set the storyboard as the main one for the application and iOS will load it automatically.
i want to change display to an UIViewController which has view controller at storyboard from an UIViewController class which hasn't got view controller at storyboard. There is no segue at storyboard for this...
Just like this:
In your AppDelegate.m do a quick setup:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
ViewController *sourceViewController = [[ViewController alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:sourceViewController];
[self.window setRootViewController:nav];
return YES;
}
In above example replace ViewController class with your own class of sourceViewCntroller
- (IBAction) didPressMyButton {
NewViewController* newVC = [[[NewViewController alloc] init] autorelease];
[self.navigationController pushViewController:newVC animated:YES];
}
Connect this action to a button on storyboard or embed view change in any method. You will need to setup UINavigation controller first.
I'm not completely sure I understand what you're trying to do, but I think you are asking how to load a view controller from a storyboard, without using a segue, from a method in a view controller that wasn't loaded from the storyboard.
First, in your storyboard, select the view controller you want to load, and open the Identity Inspector. Set the Storyboard ID of the view controller. It looks like you want to load a MapViewController, so let's say you set the storyboard ID to map.
In your code, you can load the view controller like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *mapViewController = [storyboard instantiateViewControllerWithIdentifier:#"map"];
Once you have a reference to the view controller, you can set its properties or send it messages. You can then display it in whatever way you want - maybe by pushing it onto a navigation controller, or by presenting it, or by setting it as the root view controller of your window.
I have a chain in storyboard and I want to start (for example) second view when I have first launching app. I have some code, which only work in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
method, if I put it in
- (void)viewDidLoad
method it's not work,
the code which show my other view is:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"someId"];
[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
How can I show view, which have place in chain in storyboard when app have first launching?
Try your code in
-(void)viewDidAppear:(BOOL)animated.
For further information on the iOS viewcontroller lifecycle head over to UIViewController class reference
If you are using a navigation controller, you can simply push the second view onto the navigation stack. If you are not using a navigation controller, then you could force a segue to the next view from the loading.