Marcus
Marcus

Reputation: 9472

Double Segue IOS

I currently have a tableview that for some reason is producing double segue connections.

[home] -> [Sub view #2] -> [same sub view #3]

When I click on a row it sends me through these to the third view [#3]. This is the correct view information, but I would like to only go one step [#2]. The issue becomes important when I click back and it returns to [#2] instead of home.

To clarify in this setup [#2] == [#3]

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
    NSInteger row = myIndexPath.row;
    if ([segue.identifier isEqualToString:@"ShowLocationsTableView"])
    {
        NSLog(@"PREPARE");
        LocationsTableViewController *ViewController = segue.destinationViewController;

        ViewController.categoryDetailModel = @[_categoryTitle[row], _categoryImages[row]];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
    // I assume you have 1 section
    NSLog(@"DIDSELECTROW");
    NSLog(@"INDEX PATH %i", indexPath.row + 1);
    NSLog(@"%i", [tableView numberOfRowsInSection:0]);
    if (indexPath.row + 1 == [tableView numberOfRowsInSection:0]) {
        NSLog(@"ABOUT");
        [self performSegueWithIdentifier:@"aboutCat" sender:self];
    } else {
        NSLog(@"ELSE");
        [self performSegueWithIdentifier:@"ShowLocationsTableView" sender:self];
    }
}

Upvotes: 0

Views: 478

Answers (2)

user3740899
user3740899

Reputation: 1

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
  if (tableView == self.tableView) 
  {
     UIViewController *viewController = nil;
     if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
         viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
         //Do any setup needed by casting your viewController...
     } else {
         viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
          //Do any setup needed by casting your viewController...
     }
     [self.navigationController pushViewController:viewController];
  }
}

Upvotes: 0

Lord Zsolt
Lord Zsolt

Reputation: 6557

As iphonic said, there's no reason to do all that overhead just to use segues.

You can just edit your didSelect method and push the view controller yourself.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.tableView) {
         UIViewController *viewController = nil;
         if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
             viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
             //Do any setup needed by casting your viewController.
         } else {
             viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
              //Do any setup needed by casting your viewController.
         }
         [self.navigationController pushViewController:viewController];
     }
}

Upvotes: 3

Related Questions