Double Segue IOS



我现在有一个tableview由于某些原因正在生成双segue连接

(家)->(子视图# 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];
    }
}

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

最新更新