0

I have an UItableView from which i want to move on other view controller. for do this what other suggest and what i do previously is drag and drop a segue from table view cell to other view and set an segue identifier.

i know this way and work fine in many cases but my cells are large in quantity or may be generated on the bases of data . so i cant connect each cell with view controller and set segue and its identifier so please.

what i asking is there any way to create segue b/w to views programmatically?

i think UIstoryboardSegue class can solve this but how it work guide me.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
M Faheem Rajput
  • 768
  • 2
  • 9
  • 27
  • try this link it hopeful for u http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik Jun 12 '14 at 06:41
  • thanks @Anbu.Karthik i am also talking about SWRevealViewControllerSegue n this api i am bound to connect sidebar cells manually to other view-controller my sidebar menu item are big list i don't want to create 20+ prototype cells and create and connect segue . can you guide me please. – M Faheem Rajput Jun 12 '14 at 06:49
  • Here's a [link](http://stackoverflow.com/questions/9674685/creating-a-segue-programmatically) might be helpful to u. – nikhil84 Jun 12 '14 at 06:56

3 Answers3

1
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];



if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
    SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;

    swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {

        UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
        [navController setViewControllers: @[dvc] animated: NO ];
        [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
    };

}

}

in another choice

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   
    if (index path.row==0)//just like assign the row index
    {
       [self performSegueWithIdentifier:@"yourSeguename" sender:nil];
       }
  }
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
1

Instead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.

[self performSegueWithIdentifier:@"yourSegue" sender:nil];

You just have to check which cell is tapped and then perform the appropriate Segue on tap.

Hope this helps.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34
  • Instead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button ??? guide me about this i dont have any button on tableview – M Faheem Rajput Jun 12 '14 at 07:02
  • See my updated answer. That yellow button is the View Controller Button and you will have to create segues using that button. – Dhrumil Jun 12 '14 at 07:07
1

1. Create an exit segue in your main View Controller:

- (IBAction)unwindSegue:(UIStoryboardSegue *)segue
{
    // Without naming a segue
    if ([segue.sourceViewController isKindOfClass:[MyOtherViewController class]])
        // Returning from MyOtherViewController

    // Using a segue name
    if ([segue.identifier isEqualToString:@"MySegue"])
    {
        // Do something
    }
}

2. You can find your segue on the Document Outline like so:

Your Unwind segue

3. Control + drag from the yellow to the green icon should show you your exit segue:

Connect in Interface Builder: Exit segue

4.

Name you segue:

enter image description here

Call it:

[self performSegueWithIdentifier:@"MySegue" sender:self];
bauerMusic
  • 5,470
  • 5
  • 38
  • 53