ios - 双Segue IOS

标签 ios iphone objective-c xcode segue

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

[home] -> [ subview #2] -> [同一个 subview #3]

当我点击一行时,它会通过这些将我发送到第三个 View [#3]。这是正确的 View 信息,但我只想走一步 [#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 所说,没有理由仅仅为了使用 segues 而做所有这些开销。

您可以只编辑didSelect 方法并自己推送 View Controller 。

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

关于ios - 双Segue IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24859167/

相关文章:

ios - UIFont is not convertible 错误

ios - 在 AFNetworking 中,#ifdef _SYSTEMCONFIGURATION_H 是什么意思?

ios - 具有多个选项卡的选项卡栏仅使用一个 View Controller

上传应用程序时 iOS "URL schemes found in your app are not in the correct format"

ios - 快速错误: fatal error: Cannot index empty buffer

iphone - Skybox OpenGL ES iPhone和iPad

iphone - iPhone 上的 UIModalPresentationFormSheet

iphone - cocoa 中的小写 "k"

objective-c - 如何将十六进制转换为RGB

ios - iOS 6 上的 UIButtonTypeSystem