I have a big storyboard in xcode and by mistake I have refactored some of my view controllers into a new storyboard. Is it possible to unrefector those view controllers to the original storyboard? I can't undo cause it doesn't work.
I have searched around but it seemed nothing is available. Or it is not possible?
Regards
Xcode doesn't have a unrefactor function from what i know.
However, you can actually just mouse drag over all the ViewControllers in your new storyboard and just copy paste it back to your original storyboard. The segue from one ViewController to another should still remain.
The only extra step you have to do is - manually revert the segue from pointing to new storyboard to the correct ViewController.
Related
I have a Storyboard where I have for example a UITableViewController with some incoming and outgoing Segues. Let's say I want to make this UITableViewController a UIViewController. Currently I would delete the UITableViewController, drag a UIViewController on my Storyboard and recreate all the Segues.
Alternatively, I would split my Storyboard using Xcodes Storyboard refactoring so that I at least only have to recreate all the outgoing Segues. But this cannot be done or at least is not practical in some cases where I want my ViewControllers to be in the same storyboard because they belong together.
As you know, this is cumbersome and I think it is prone to error.
So my question is: Can I replace a ViewController in my Storyboard without losing the incoming and outgoing Segues?
As I know it isn't possible with IB. It's only possible to exchange the controller class name in the settings. But a UITableViewController has additional settings that wan't disappear/appear by a simple rename.
My suggestion is to create the new view controller, link the seques one by one and than remove the no longer linked UITableViewController.
(That's one of the several reasons I do not use storyboards anymore. Instead I try to implement screens independent of each other, so I can change flow and/or replace single screens more easily.)
Unfortunately Xcode does not have this, at least as of 9.2. The solution is to edit the storyboard file in an editor, but it's really not so bad.
Get the Object ID of the controller you want to replace, and the one that will replace it. It's in the Identity Inspector, Document section, labeled Object ID.
Make sure you save the Storyboard before editing it outside of Xcode.
Each of the segues looks like this in the storyboard file:
<segue destination="S3O-z0-PFf" kind="showDetail" identifier="abcde2" id="x0q-y6-ZkJ"/>
Replace the destination ID with the new view controller's Object ID:
<segue destination="b5A-4F-zOe" kind="showDetail" identifier="abcde2" id="x0q-y6-ZkJ"/>
Save the file, and Xcode will reload it automatically. The segues will point to the new controller.
I'm currently developing a framework in Swift that includes a storyboard that I designed myself. What I need to do is that the user that uses my framework can create a segue to my storyboard. Then I'd like to be able to recreate a segue to the user storyboard that that I "leave" my storyboard.
How could I do so ?
Thx !
Your question is vague and I am not entirely sure what you are asking. However, I can't comment yet so I will try to answer with what little I know. It seems like you are asking how to transition storyboards. The simplest way is using a UIButton in your storyboard. Open up storyboard and go to the navigation controller. Then, add a button to the Nav Controller. Right click (or control click, depending on your settings), and drag the line to the main storyboard. Lastly, click on the show option. When a user clicks on the button, it will immediately switch to the main view controller. Don't forget to add the button in the view controller. Hopefully, this is what you meant and helps. If you wish switch view controllers in code, this is a duplicate and you should go here: How to switch view controllers in swift?. If this doesn't answer your question, comment and I will try and help. For future reference, please provide more information: snippets of code, pictures, anything that better demonstrates your problem.
I fixed it by getting the instance of a new view controller added on the user storyboard with the view controller identifier like so :
ProcessOut.backViewController = storyboard?.instantiateViewControllerWithIdentifier("back")
And then I present it like I would present a normal viewController from my storyboard.
I'm a beginner to iOS development, so forgive me if this is really basic. It's probably answered somewhere, but I've looked for a long time, and I'm struggling.
I have a second View on my story board that I've successfully linked to the first view using a Navigation controller and stuff, and I'm able to navigate to it. I can also add actions/outlets from elements on my first view by Control-dragging to the .h file.
I have a label on my second view, and I want to be able to do the same: add actions and outlets from elements. But when I try Control-dragging, nothing happens. What am I doing wrong, and how do I fix it?
Hmm, well first of all welcome to Stack Overflow! And thanks for asking the question.
Let me know if I have this right - you have two view controllers to the right (linked with segues) of a navigation controller and currently you can navigate to the second from the first using a button at the top right? Then when on the second view controller there's a nav button at the top left with a little arrow by it? And this should take you back to the first. Is that right?
Now on the second view controller you want to create a button that performs an action, but when you right-click-drag (ctrl-drag) onto a .h or .m file nothing happens?
If that's the case I've seen a few reasons for that. You might try:
You need to make a button, a label can only recieve actions, not create them. Read this article on IBOutlet vs IBAction
Restart Xcode (I know, it's lame, but humor me)
Make sure you're dragging (if on the .h file) between "#interface" and "#end"
Make sure you're dragging (if on the .m file) between "#implementation" and "#end"
Do you have a custom view controller class for your second view? If so, select the second view controller in your storyboard and go to the identity inspector. Set the custom class to your custom view controller's class name. Now you will be able to control-drag IBOutlets and IBActions.
I am new to iOS programming and I am working on a project which will use both XIB files and storyboard.
I have two modules in it basically. First module is made from XIB files which also runs independently. I have made another module using storyboard and I had to integrate these two independently running modules. The screen of my first module which I want to connect to my storyboard is a subclass of UIViewController and I was able to do that with the help of stackoverflow (How to load a storyboard from a XIB file?) by creating an object of UIStoryBoard. Now my application is able to go to the storyboard but I can't come back to my first module which is made up of XIB files.
Please let me know how can I connect to the same instance of the last screen of the first module through which storyboard is called so that I can move back and forth through these views easily. Connecting to the same instance of the XIB file is important because it is a chat screen and when I come back to this screen, I would like to get back to the chat where I had left it and also when I come back to the storyboard (by clicking a button on the chat screen) I have a slider on the screen which should display the value which the user must have chosen when they were on this screen last time. I guess creating a new object should give me a new screen which won't work in this situation. This kind of mechanism works well within storyboard with the use of segue where we can define both source and destination view controller.
Please help me achieve the same in my situation.
Please also check the screen shots of the XIB file and the storyboard which I want connected.
Thanks.
Convert the nib files into storyboard, it will help you easier to manage your application.
Well in your case, what i see is from nibs is that there is a navigation controller in storyboard and also there will be a root view controller navigation controller from xib files.
Well the navigation controller stack has all VCs you pushed into and you can get back it in different ways.
I start my app in landscape for iPad. A nav controller holds my tableVC I click on a cell we push a new VC onto the stack. That works fine. The problem is, when I press the standard "back" button on the nav controller, my app gets forced into portrait and my tableVC is off of the screen. I am doing no manual positioning of views. This doesn't happen if I start the app in portrait mode.
How do I fix this abnormal behavior?
Notes: There is also a tab bar present in the app if it matters.
Upon further testing, if I load the NavController in portrait (with the first view being the table view) then switch it to landscape, then select the cell, then press back, it works fine. So the problem only happens if i start the app in landscape and never turn it to portrait.
EVERY VC has shouldAutoRotate set to return YES. I have subclassed the tab bar and done the same. I am wondering if this is a bug. Perhaps the problem lies in the fact that I took existing .XIB files and their views that were created for iPhone, then copied and pasted them, then deleted the iPhone specific views and then added iPad views.
If your subclassed TabBar Controller returns yes, and ALL of your VCs return yes for shouldAutoRotate, then the problem lies within your xib files. Though your explanation makes it sound like the VC you are pushing doesn't return yes, you've stated that it does, so it must be the xib files.
In IB, try setting the default orientation of your xib views to landscape, clean - build and run.
That may provide a clue or two.
Maybe you can create a new and simple iPad application with just a tabbarcontroller a navigation controller and 2 viewcontrollers to test if the cause is or is not the recycled iPhone .XIB files.
Also you can Command+Shift+F to search in the whole project for ": UIViewController" to double check that every VC has shouldAutoRotate set to return YES, in case you have third party code in your application that has a subclass of UIViewController on it. (the search will return a list of headers files that inherits from UIViewController).
I had had similar problems with really weird behaviors that were fixed by deleting the .XIB file and made it again.
Good luck finding the problem =)