Reputation: 3569
I inherited a swift project that I need to change: I need to add a line in the list of settings, with a segue to a new ViewController.
Is this the correct order of actions:
first build the new ViewController (can I copy-paste from another ViewController?)
then add a new line in the "settings" list ( can I copy-paste another listItem?)
then add a segue from the new listItem to the new ViewController ( any hint on how to do it is welcomed...)
or
what is the correct way?
( I did the same change in android project, changing android.activity.xml is much more easier than using xcode.storyboard.userInterace )
Upvotes: 0
Views: 156
Reputation: 936
I would recommend to use separate .xib for the new ViewController (IMO it will be much easier and harder to mess things up)
actions:
add new line in the settings (with it's own action). Without any code it's hard to say if you can copy any of the previous but I would assume you can (if it's in the storyboard just check the outlets of the copied and remove them)
Create new ViewController with .xib file (File -> New -> File -> Cocoa Touch Class (subclass of: UIViewController
, make sure also create XIB file
is checked)
In the action of the item (assuming the previous ViewController is embedded in NavigationController)
let myNewFancyViewController = FancyViewController()
show(myNewFancyViewController, sender: self)
EDIT:
Since you added image of the storyboard:
Settings
looks like to use static table view cells, it should be easy to copy one of them and add it where needed. Copying ViewController is also possible just make sure that all outlets (views/actions) are removed. Last step is just to option
+ drag from the cell that you created and select show
(You can add identifier
to the segue if you want to pass data between the view controllers)
NOTE: after copying the new view controller seems to remove all the existing outlets, so it shouldn't be a problem
Upvotes: 1