Segue to another storyboard - ios

I dont know how create segue from storyboard 2 to storyboard 3(image: https://i.stack.imgur.com/NLhJY.png). Afterwards user tap save button(storyboard 2), i need save item and open saved item on storyboard 3. I try use Unwind Segue, but this doesnt work.
I try use instantiateViewController. I set on storyboard 3 Storyboard ID("Item") and then add this code to save button:
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Item") as! ItemViewController
self.present(viewController, animated: false, completion: nil)
But when Storyboard 3 open, after tap Save Button on Storyboard2, navigationbar on Storyboard 3 doesnt showed. Anyone can help find me solution to this problem?

You need to specify which storyboard you want to use exactly along with your ViewController identifier.
Try this:
let storyboard: UIStoryboard = UIStoryboard(name: "YOUR_OTHER_STORYBOARD_NAME", bundle: nil)
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Item") as! ItemViewController
self.show(viewController, sender: self)

Related

present UIViewController programatically

When I click on the newPostButton, I want to segue programmatically to the NewPostVC (which is that view on the right side).
However, the view does not show up on the simulator, as you can see, it's completely black.
What is the issue, why isn't the view showing up?
And how to fix that?
Thank you guys
If I understand correctly you are trying present view controller on your Navigation stack so you need to do two thing set storyborad ID and set push viewController here is code :
Set 1:
set Storyboard ID : NewPostVC to your NewPostVC Storyborad
Step 2:
#IBAction func newPostClicked(_ sender: UIButton) {
let storyborad = UIStoryboard(name: "Main", bundle: nil)
if let vc = storyborad.instantiateViewController(withIdentifier: "NewPostVC") as? NewPostVC {
self.navigationController?.pushViewController(vc, animated: true)
}
}

How do I programmatically pull up a different storyboard when a button is clicked in Swift 4? [duplicate]

This question already has answers here:
Segue to another storyboard?
(6 answers)
Closed 3 years ago.
Here is my code so far
joinButton.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
}
#objc func buttonAction(_sender: UIButton) {
print("I want to go to a storyboard here")
}
I have everything coded (never used storyboard), but now I want to actually manually play with the UI now. How can I manually play with the storyboard? Or even render out to a different viewcontroller? Thanks!
You can do it programatically this way:
Swift 3+
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ViewControllerID") as UIViewController
present(vc, animated: true, completion: nil)
You need to assign a Storyboard ID to the view controllers you are going to use programatically:
Select storyboard
Go to Identity Inspector (⌥⌘3)
Assign Storyboard ID
If you want to add manual segue in Storyboard (Note: you can have multiple manual segues):
Select storyboard
Select the source view controller
Go to Connections Inspector (⌥⌘6)
In the Triggered Segues, drag the dot beside manual to the target view controller and select the desired method
In Document Outline, select "Show segue..." and go to Attributes Inspector (⌥⌘4) and assign an Identifier
In your button function, you can simply use the segue by:
self.performSegue(withIdentifier: "<IdentifierForSegue>", sender: self)
Or if you do not wish to use a manual segue:
// If view controllers are in the same Storyboard
let storyboard = self.storyboard!
// If view controllers are in different Storyboards
// let storyboard = UIStoryboard.init(name: "<NameOfYourStoryboard>", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "<IdentifierForTargetViewController>")
// If you don't have a navigation controller
self.present(viewController, animated: true, completion: nil)
// If you have a navigation controller
// self.navigationController?.pushViewController(viewController, animated: true)

how to open UIPageViewController on button click

Looks like duplicate right ??
but i dig the internet and i found nothing ..
please someone help me how to open UIPageViewController on button click
if we want to open uiviewcontroller we can use this
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
but what about UiPageViewController ??
how to achieve that ??
You can use a storyboard segue. Make sure that your initial VC is embedded in a NavigationController. Then create a segue from initial to your pageViewController and give it an ID.
Next, in your initial view controller code, instead of instantiate, do push.
self.performSegue(withIdentifier: "seguetoPVC", sender: self)
Put that in your button click and it will allow you to open your PageViewController on button click. Hope this helps.

Programatically creating Segues in ios swift

In my app I use side bar as in facebook. when the user slides out the side bar a uiimageview is displayed. when user taps on the image it takes hm to a different viewcontroller. the problem i am facing is that I have created sidebar programatically and the other view to which I want to navigate the user is created using storyboard. So my source view is created programatically and destination view is created using storyboard. So can someone explain me if there is any way of using "Segue" in this scenario. Since i can not create segue using storyboard I need to do it programatically but even after a lot of googling i could not find the answer.
Well, to get another instance of another storyboard programmatically you can use something like:
let newController = UIStoryboard(name: "MyStoryboard", bundle: nil).instantiateViewControllerWithIdentifier("MyIdentifier") as! MyViewController
and then you push to your navigation controller, or add as a child view controller or something...
If you don't wanna bother with identifiers you can just use the instantiateInitialViewController instead of instantiateViewControllerWithIdentifier
Might help
"userSB" is the viewcontroller storyboard identifier
#IBAction func tapSearchCriteria(_ sender: Any?) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let aVC = storyboard.instantiateViewController(withIdentifier: "userSB") as? AViewController
aVC?.modalPresentationStyle = UIModalPresentationStyle.custom
aVC?.transitioningDelegate = self
aVC?.udelegate = self
self.present(aVC!, animated: true, completion: nil)
}

Manual segue with SWRevealViewController in Swift

There is a great blog post over at http://www.appcoda.com/tag/swrevealviewcontroller/ that goes in to setting up SWRevealViewController which is a great component for slide out side menus (https://github.com/John-Lluch/SWRevealViewController)
Unfortunately, there are no swift examples of how to perform a manual segue.
Took a cleaner approach to storyboard support. SWRevealViewControllerSegue is now deprecated and you should use SWRevealViewControllerSegueSetController and SWRevealViewControllerSeguePushController instead.
I've tried something along the lines of:
let navigationController = self.window?.rootViewController as! SWRevealViewController;
let viewController = navigationController.storyboard?.instantiateViewControllerWithIdentifier("ImportFileSelect") as! ImportFileSelect
navigationController.showViewController(viewController, sender: self)
This doesn't work though. Any ideas? I've trawled the web for swift examples, my next step is to learn objective c!
In order to work you'll need to following steps:
You need to instantiate the SWRevealViewController and then attach it
to the root controller.
Then instantiate the destination controller.
Then create a navigation controller and set the destination
controller as the rootViewController
Finally push the navigation controller with SWReveal
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController
self.view.window?.rootViewController = sw
let destinationController = self.storyboard?.instantiateViewControllerWithIdentifier("StoryboardID") as! NameOfViewController
let navigationController = UINavigationController(rootViewController: destinationController)
sw.pushFrontViewController(navigationController, animated: true)
I've kind of made some progress. I can load in a new view controller, but it doesn't animate in anyway. The code to do this, on a button click is:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("TARGET_VIEW_CONTROLLER") as! UIViewController
var rvc:SWRevealViewController = self.revealViewController() as SWRevealViewController
rvc.pushFrontViewController(vc, animated: true)
Download SWRevealViewController project's zip form Github.
Drag SWRevealViewController.m and SWRevealViewController.h files from zip (SWRevealViewController folder) to your project, and Click “Yes” to the prompted message "Would you like to configure an Objective-C bridging header?"
Take a look at storyboard in RevealControllerStoryboardExample2 project. Design your storyboard with this example.
This is not how it should be done, but at least i found a way to do it.
In the TableViewController where u have the slideOut menu do something like:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.row == <some position> ){
let vc: AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_DESTINATION_IDENTIFIER")
self.showViewController(vc as! SWRevealViewController, sender: vc)
}
The one that satisfy the condition will segue with default animation, not like the slide out menu normally does.
After, in storyboard, do a normal Reveal View Controller Push controller, and as long as it doesn't satisfy the condition it will exit the slide out menu normally

Resources