Same segue for more actions in Interface Builder - ios

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.

Related

How can I create a custom segue from a custom collection view cell (cell created using xib) to a tabBar controller

I created a collection view that has custom cells created using a .xib file. I need to create a custom segue that goes to a specific tab of on a tabBar controller depending on the label of the button of the cell. The collection view is basically used as a menu for going to a specific tab of the tabBar controller.
The xib of the custom cell of the collection view has a class of its own. The cell has a button. On clicking the button I need to perform a custom segue (because i need custom animation) from the view controller to the tabBar controller. The collection view is present on the view controller.
Maybe you should explain better the state of the views in order to know if you want to push to another view or simply change the current tab. Anyway, I think you don't need a custom segue, just use the didSelect of the cell, e.g. for obj-c
tabBarController.selectedViewController = [tabBar.viewControllers objectAtIndex:SPECIFIC_TAB];

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.

Creating a TabBar segue to another tab via Storyboard

I have found multiple questions related to creating the prepareForSegue method and all that. What I am a bit lost on is how do I create a segue from say my first tab to the second.
Do I create it like I create a segue with a button. I tried starting the CTRL + Drag to the other view, but nothing seemed to highlight? I have a:
Tab Bar Controller -> Tide Detail View + Tide Table View
I cant seem to find any results on creating that segue ID via the Storyboard. Is the segue between the tabs built in due to the nature or a UITabBar
The trouble with trying to segue between tabs of a tab bar controller is that segues are expected to be to new view controllers not existing view controllers. There is no built-in way of using segues to switch tabs.
The standard way of switching tabs is to set self.tabBarController.selectedIndex.
Not happy with this option, I created JLTTabSegue as a custom segue to switches between tabs.
Either go the standard route and skip segues altogether, create a custom segue to do it, or try mine if you like.

Segue between ViewControllers without trigger control?

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.

Resources