双Segue IOS

时间:2014-07-21 06:51:31

标签: ios iphone objective-c xcode segue

我目前有一个tableview,由于某种原因产生双segue连接。

[home] - > [子视图#2] - > [相同的子视图#3]

当我点击一行时,它会通过这些将我发送到第三个视图[#3]。这是正确的视图信息,但我只想走一步[#2]。当我点击它并返回[#2]而不是回家时,问题变得很重要。

在此设置中澄清[#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];
    }
}

2 个答案:

答案 0 :(得分:3)

正如iphonic所说的那样,没有理由只使用segue来完成所有开销。

您只需编辑didSelect方法并自行推送视图控制器。

- (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];
     }
}

答案 1 :(得分:0)

- (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];
  }
}