Segue between ViewControllers without trigger control? - uitableview

Is there a way in Storyboard UI to connect two UIViewControllers by a segue, without setting an object (Button, cell, ...), triggering the segue?
I want to fire the segue in code with performSegueWithIdentifier:sender: programmatically.
Why i want this is, i'd like to display a detail view controller, when a tableviewcell is selected, but only while the tableview is in editing mode.

You can just control-drag from one view controller to the other. And then of course don't forget to give the segue an identifier.

Related

Why UIBarButtonItem doesn't call IBAction before segue?

My question is very similar to : Swift: Make button trigger segue to new scene
The issue is:
I have a view controller, with a button that causes another view controller to appear modally.
I have Ctrl+Click from the button to the second View Controller, and created the segue in IB.
Then I Ctrl+Click from the button again to the source code of the view controller to create an IBAction method.
I assumed that the button will do two things now: a) call the IBAction method , and b) perform the segue.
What happens is only the segue for some reason.
When I delete the segue, or remove the call to the view controller from IB, then the IBAction is called, but Xcode tells me that the second view controller is not reachable now.
I want to be able to present an ActionSheet to the user and then be able to performSegue to the second view controller, based on what the user selected from the action sheet.
I know I can programatically call performSegue but that requires the creation of the segue and attaching it to a physical button in IB, which defeats the purpose of not calling the IBAction that button may already have.
If I want to do some additional steps before calling the segue I usually attach an IBAction to the UIButton and call the perform segue from within this, in the code. You can add a segue to the storyboard and give it an ID, without having to connect it to a button. You do this by control-clicking on the viewcontroller and drag to the next viewcontroller in the storyboard.
Connecting a segue from storyboard will automatically always perform the segue. You can do any preparation for transitioning to the new view controller in the prepareForSegue method.
If there is some logic that comes before, like a user selecting something from the action sheet, just use the IBAction and then perform the segue with performSegueWithIdentifier based on the user selection. However, you do not have to create another button, just ctrl+drag from one view controller to another and give the segue an identifier.

UIPickerView selection link to UITableView

How do I link a UIPicker view on one scene to a UITableViewController? I have a picker view in one view controller populated with a number of categories, I want to segue to a table view controller when a category is selected/pressed.
First, create the segue in the Storyboard by Ctrl-dragging from the view controller to the new TableViewController (don't link from the picker, link from the view controller in which it appears). Select the segue and give it an appropriate identifier. In your UIPickerView delegate, implement the pickerView:didSelectRow:inComponent: method, and save the selected rows/components to properties. Then invoke performSegueWithIdentifier:sender: to trigger the segue.
Separately, as part of the prepareForSegue method, read the properties you previously saved, and set the relevant properties of the segue destination view controller.
NB you may find, though, that this will trigger if the user hesitates whilst spinning through the picker view options.

Same segue for more actions in Interface Builder

I want to perform same segue on both table view row selection and bar button item tap actions. Is there any possibility to do it in IB (without code performSegueWithIdentifier(_:sender:))?
I do not want do create brand new (same) segue for both actions. Just reuse the one. Something like wire it up with the existing one...
You can have multiple segues from one VC to another, but the catch is that they have to have unique segue identifiers. Just ctrl+drag from your table cell to the destination VC to create one, then do the same from your bar button item too create the other.

How to disable storyboard segue but still use segue identifier?

When I transition from a table view cell to another view controller, I can connect it on storyboard. However, this doesn't allow me to use didSelectRowAtIndexPath: method even when I want to use selected row and indexpath logic or pass a value between the two view controlelrs to make a transition.
But when I disable the storyboard segue transition, I cannot set segue identifier and hence cannot call performSegueWithIndentifier: method from within the above method.
So how can I use didSelectRowAtIndexPath: and still perform a segue? If I set my storyboard segue and at the same time define didSelectRowAtIndexPath:, my app crashes after I return back to the original view controller.
Just create your segue from the viewControler button (yellow button on bottom) of viewControler1 to somewhere in the viewControler2

iOS - Push Segue not working even with NavController

I'm trying to set up a basic "Newsfeed" function for an iOS app, with headlines in a TableViewController segueing into a simple ViewController to display the text of the selected story. I'm using Storyboards to set up the segues, and I can't get it to work...
What I've Done - I started by CTRL+Dragging from the Cell of the TableView onto the secondary ViewController and choosing "Selection Segue - Push." Then I clicked on the segue and gave it the identifier "newsArticleSegue," and I embedded the TableView in a Navigation Controller. I've got the TableView data source hooked up to a plist file as well, although I don't think that would have any effect on the segue, right?
All that happens when I run the app and click on a row of the TableView is that it gets highlighted blue. Clearly the segue isn't working, but the tutorials I've found only list those steps, as though that's all that's needed...
Can anyone tell me what I am missing? And thank you in advance!
When you create the segue with IB, you can drag from the view controller (which you did) or from the table view cell, which will call the segue if the table view cell is selected.

Resources