Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a push segue when a UITableViewCell is selected

I have a list of effects in a table view. I have created a top right bar button which does a push segue to another view controller which helps create a new effect. Now I want to add push segues to the table view cells so that the effects values maybe loaded on the add effects view controller and I can save the edited values.

The question is can I create a push segue programmatically? If not can I pass the effect through a prepareforsegue? If I try to use a prepareforsegue, I run into a problem where control dragging from the UITableView does not let me create a push segue to the add effects view controller.

like image 993
Aviral Bajpai Avatar asked Mar 31 '14 10:03

Aviral Bajpai


People also ask

How do I segue from Uitableviewcell?

So, select the first view controller, and then go to the top menu and click on Editor → Embed In → Navigation Controller. For this, we are going to select the “show” segue in the “Selection Segue” section. This means that when you tap on the cell, it will cause this segue to happen.

What is push segue?

A push Segue is adding another VC to the navigation stack. This assumes that VC that originates the push is part of the same navigation controller that the VC that is being added to the stack belongs to. Memory management is not an issue with navigation controllers and a deep stack.


1 Answers

control drag From View Controller to View Controller

From View Controller to View Controlle!

You will need to give an identifier to your segue:

enter image description here

Perform the segue:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     [self performSegueWithIdentifier:@"yourSegue" sender:self]; } 

Now here is the thing, this will just perform the segue, if you ever needed to pass some data to that view controller. Then you have to implement the following segue delegate:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {     // Make sure your segue name in storyboard is the same as this line     if ([[segue identifier] isEqualToString:@"yourSegue"])     {         //if you need to pass data to the next controller do it here     } } 
like image 195
meda Avatar answered Sep 22 '22 12:09

meda