I want to swap out one view controller for another in an existing XCode iOS storyboard, but I'd rather not recreate the segues going to it. Is it possible to move or adjust the destination of an existing segue?
I believe you do need to create the new segue(s), but that's as easy as control-dragging between the source of the segue and your new scene. And if your code is doing anything that requires the storyboard id (such as prepareForSegue or performSegue), then just apply the same storyboard id for your new segue and you don't need to change your code. If you're using a custom segue, you can just use the same segue class, so you don't need to change the code just because the destination changed. And if the source of your segue is a button or something like that, when you make the segue to the new scene, your old segue is automatically removed, so that simplifies the process, too.
In short, you probably do need to recreate the segues, but you probably don't need to change your code too much to support that.
Related
How do you change the endpoint of an existing segue using storyboard?
Obviously I can delete and re-create the segue but this adds a potential for "operator error". Eg if I accidentally mistype the segue's identifier, the code will later crash.
Storyboard doesn't seem to offer this really simple functionality. Can't drag the segue to somewhere else, can't see any config items that refer to its endpoint. Or am I missing something obvious?
Yes, you can't change endpoints of existing segue. You have to create new one. You can't drag and drop endpoint to some viewcontroller to other.
And there is no need of it also.
For example, let's assume scenario like : You have one view controller called A, and you have given segue from A to another Viewcontroller B and segue name is segueToB. Now you have another viewcontroller say C and now you want to give segue from A to this C then make Another segue. no need to delete segueToB. Create segueToC which points A to C. Now when you want to go from A to B then perform segueToB segue. When you want to go from A to C then perform segueToC segue. Likewise you can make multiple segue. There is no need to change endpoint or delete segue and change identifier everytime.
How should I go about creating a View for the storyboard programmatically? I want to access the labels from the first ViewController object made(automatically to call the IBAction methods of VC). I know that this first object of VC is the one linked to the view in the storyboard(?) and I need to change a label form another file, besides VC. I'm pretty sure the only way to do so would be to access the VC object that is linked to the view, or create one and not go with the default one that is created. If not, how would I go about accessing the labels of the view from another file?
You don't create storyboard objects programmatically. A storyboard is very basically an XML file Xcode uses to call different view controllers. The biggest advantage of using storyboards over NIBs is you can layout transitions or segues, and the advantage of NIBs or storyboards over initiating view controllers by code is obviously the visual interface. So your question doesn't really make sense.
If you want to reference a particular view controller's label from your storyboard you need to create a pointer to that view controller first, but changing it programmatically doesn't make sense because that's what storyboard is for.
That said you may just need to go look for your class name in your view controller's Identity Inspector in storyboard and then edit your label programmatically through an IBOutlet property.
I have a question about how I use segues with Storyboard in Xcode.
I have an application with 3 views, and I would load them with animation modal "Cross Dissolve".
Every time I load a new view without dismiss the current one, it still occupying memory?
I'm realizing that after changing multiple views my APP becomes slow.
If yes, how is the right way to change views in sequence?
When you go back from 3 to 1 you should use an unwind segue. That will cause 3 and 2 to be deallocated (if you're not keeping a strong pointer to them), and you will actually go back to the same instance of 1 (rather than creating a new one). In general, you should not go backwards using a segue other than an unwind segue.
Rather than specifying the "back to 1" segue in the storyboard, you may want to instantiate it in code using the method -initWithIdentifier:source:destination:. That'll permit you to specify the destination as your first view controller instead of creating a new view controller to transition to.
In fact, you should probably specify all the segues between these view controllers programmatically if you don't want to instantiate new copies with each switch.
I need to create two Segue's from the same button, and then I want to programatically choice which one to use based on device orientation. The problem I'm having is that you can only seem to create one segue from a button to another view so when I add the second one it just changes the first.
How do you add a segue that either isn't linked to a button etc so I can do programatically or how are you supposed to do this. I want to have two views that get dynamically picked based on orientation rather than moving the objects based via code when rotated as there is alot of objects and custom stuff that would make it much simplier just to have two views.
You'd have to trigger the segue manually. Hook up the button to a method, then make two segues, one from each view controller to the other in your storyboard, then give it an identifier in IB, then in your method you can call "performSegueWithIdentifier:".
Additional Info
To make a manual segue, control-click from the view controller object in IB to another view controller and the box will pop up as "Manual Segue". Just make sure it has an identifier.
I would think you could have the button trigger an IBAction wherein you could make a choice based on orientation and then trigger the appropriate segue programmatically.
When I click a control, I want it to push a new view controller to both the Master Split and the Detail Split.
Unfortunately, in the Storyboard editor, when you control drag from an object and create a segue to a View Controller, it overwrites the original value of the Push Storyboard Segue field.
Is it possible to accomplish my goal in the storyboard file, or does it have to be done in code?
You'll probably have to override -[UIViewController prepareForSegue:sender:] and do the extra push yourself; storyboards are designed to manage the navigation flow for a single view controller at a time.
I think it would be much nicer and cleaner if you would just Control+drag, but don't leave the segue with a default, "Push" style. Notice that there is also "Replace" style available for segues here. When you choose "Replace" style, there will be "Destination" parameter available. Choose whether you want to replace a view in Master, or Details controller, and that's it.