I am using StoryBoards and am trying to overlay a View Controller's view on top of another View Controller's view so that the two are visible (the top one has a couple of transparent areas).
If I connect the two together with a modal Segue and then call [self performSegueWithIdentifier:#"showTutorial" sender:nil]; the source view is removed and the destination one is shown. No joy.
If I connect them with a push Segue, calling [self performSegueWithIdentifier:#"showTutorial" sender:nil]; doesn't bring up the new view. Embedding the source view controller in a Navigation Controller brings up the destination view, but also removes the source view. No joy.
Any suggestions?
#Inafziger: I thought I would have been able to do that with a segue, but segues are not the way. Also, as I wanted to keep working with the Storyboard and avoid making a new nib file from scratch, here's what I did:
tutorialView = [self.storyboard instantiateViewControllerWithIdentifier:#"Tutorial"];
[self.view addSubview:tutorialView.view];
Then in the Storyboard, write "Tutorial" in the ViewController's Identifier field.
Related
I have created several .xib files with a navigation controller and some table view.I have a barButton. when I click that one it pushes one view onto another, now I want to come to the previous view, that one can be done by push. But my previous view is embedded in a navigation controller(here I can see the previous view but with all navigation functionality disable). So here I want to perform unwind segue like we do in storyboard. But I am not using any storyboard. I just want to know that what can I do to get the similar result as unwind segue while using only .xib files?
use [self.navigationController popViewControllerAnimated:YES] in the view controller from which you want to perform the unwind segue.
I have ViewcontrollerA , which is a view made in storyboard.
In this view, i have a UIView that i have added in storyboard and create an outlet to it called containerView.
I wants to add some other viewControllerB (also made in storyboard) to the container.
Tried that :
//add to container a new view from storyboard,with id called serviceView
UIViewController *sv = [self.storyboard instantiateViewControllerWithIdentifier:#"ServiceView"];
[self.containerView addSubview:sv.view];
and got a crash.
How can i do that ?
Thanks .
It most likely crashed because sv is nil, though you should have posted what reason it gave for the crash in your question. If this is the reason, it's probably because your storyboard doesn't contain a view controller with that storyboard identifier. But even if you fixed this, this isn't the proper way of doing view controller containment.
As for adding a view controller to another view controller, you need to use the view controller containment API added in iOS 5. In fact you can even use the storyboard to do view controller containment without writing code. From the Object Library, you can drag out a "Container View". It will let you attach another view controller from your storyboard graphically.
I'm still pretty new to Obj-C and iOS so bear with me. In my app I am trying to implement a share button that brings up a second view in the current view controller. I'm following this tutorial(http://www.youtube.com/watch?v=DZ3SyGInklQ) and I run into a problem where the dev uses initWithNibName and I am using a storyboard. I'm wondering why my second view is not coming up when I press my button. It's probably very obvious but I can't figure it out.
Heres some of my current code:
Menu.h
//Share button
- (IBAction)shareButton:(id)sender;
Menu.M
- (IBAction)shareButton:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MenuStoryboard" bundle:nil];
UIViewController *sharebuttonview = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:#"sharebuttonview"];
[self presentViewController:sharebuttonview animated:YES completion:NULL];
}
First you go into the storyboard and then you connect the Share Button with the View you want to show. After that you name this segue with an Identifier.
In you Menu.M in the IBAction you write:
[self performSegueWithIdentifier:#"mySegueIdentifier" sender:self];
(mySegueIdentifier is the Identifier you used before)
Based on your description of the issue it appears that you may want to do a manual segue, which allows you to open a target view controller from any number of UI controls. The workflow has changed from Xcode 5 compared to prior versions of Xcode. You may want to see my blog post for additional tips but essentially you will want to open your storyboard and do a Ctrl+Drag from one view controller in the document outline view to a second view controller.
Then you will need to name the segue that is created by clicking the Segue in the middle of the gray line connecting the two view controllers and update the segue id in the identity inspector.
In your source view controller you should be able to have any action call [self performSegueWithIdentifier:#"MySegueID"];
Additionally, you can add a prepareForSegue method to the source view controller, which allows you to initialize and pass information to the target view controller.
Apple has a sample project that you can download to see this workflow in detail (MultipeerGroupChat)
Hope this helps.
I'm trying to trigger a storyboard segue from a UI element which isn't in my storyboard (in this case, it's a UIAlertView). As such, I can't draw the arrow from any of the existing components in my storyboard.
What's the proper way to deal with this situation? I need a segue with an identifier, so that I can call it from the relevant UIAlertView button.
You can add your segue by right click + drag from your source controller to your destination controller in your Storyboard. Then just click on the created segue and set the identifier.
You can trigger your segue programmatically like this:
// Note: In this example self is the source controller
// (the controller that holds the segue)
[self performSegueWithIdentifier:#"mySegue" sender:self];
Here is a screenshot you can use as a reference:
My UINavigationController contains a UIToolBar with 3 UIBarBottomItems - It has all been drag/drop designed in the storyboard. I want this UIToolbar to be shared on all my views. I have therefore set checked the "shows toolbar". But when I run it the UIToolBar is empty in all of my views. What could be the reason for this ?
I realize this is an old thread but I've just been struggling with this for a couple hours and finally figured out what was wrong. It was something simple so thought I would share. I was calling [self.navigationController setToolbarHidden:NO]; in viewDidLoad. The problem was that viewDidLoad is called before the view controller is pushed onto the navigationController so self.navigationController is nil. I moved the code to viewWillAppear: method and it worked.
UINavigationController have default toolbar. which you can use. you can use following code
[self.navigationController setToolbarHidden:NO];
in the topmost view controller and
[self setToolbarItems:items];
in all your view controllers, where items is an NSArray of that view controller's toolbar items.
select your initial view controller in the storyboard and embed it in navigation controller.
now all your pages should have the navigation bar.. if u manually dragged dropped the previous bars when u run the program it'll show both...
You'll have to remove the old ones and then modify the new one as required.