2014-07-21 36 views
0

我目前有一個tableview,由於某種原因正在產生雙重連接。Double Segue IOS

[首頁] - > [副視點#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]; 
    } 
} 
+1

你已經添加在故事板一賽格瑞呢? –

+0

不要在這種情況下使用segue,分開使用它們,並正常推送。你可以很容易地從storyboard中實例化一個ViewController而不使用segue,但是使用storyboard標識符。 – iphonic

+0

此外,你的代碼看起來很可怕(看上去)。不要使用'[]'來訪問屬性(比如'[indexPath row]',而是使用點符號)。 –

回答

3

正如iphonic說,沒有理由要盡一切開銷只是使用塞格斯。

您可以編輯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]; 
    } 
} 
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]; 
    } 
}