为 performSegueWithIdentifier() 设置 Storyboard

Setting up Storyboard for performSegueWithIdentifier()

我在我的应用程序页面上工作,用户从 UITableView 中选择 3 个单元格之一,然后转到相应的 2 个 UIViewControllers 之一,该 UIViewControllers 使用有关所选单元格的详细信息填充页面。我正在尝试准备故事板以使用 'performSegueWithIdentifier()' 执行此操作。我通过使用 'show' 方法将父视图的视图控制器与每个子视图的视图连接起来进行了转场。然后我将其添加到我的父视图控制器中:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
    if indexPath.row == 0 {
        appDelegate.selected = 1
        self.performSegueWithIdentifier("GraphID", sender: self)
    }
    if indexPath.row == 1 {
        appDelegate.selected = 2
        self.performSegueWithIdentifier("DistanceID", sender: self)
    }
    if indexPath.row == 2 {
        appDelegate.selected = 3
        self.performSegueWithIdentifier("GraphID", sender: self)
    }    
}

当我启动我的应用程序并按下任意单元格时,它崩溃并出现 NSException:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver     (<FlightTracker.StatusViewController: 0x7fe4faa5c8c0>) has no segue with identifier 'DistanceID''
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109446f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001090dfbb7 objc_exception_throw + 45
    2   UIKit                               0x0000000109b9dd3b -[UIViewController     shouldPerformSegueWithIdentifier:sender:] + 0
    3   UIKit                               0x00000001174dec78 -[UIViewControllerAccessibility     performSegueWithIdentifier:sender:] + 39
    4   FlightTracker                       0x0000000106f977e2  _TFC13FlightTracker20StatusViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCS o11NSIndexPath_T_ + 2530
    5   FlightTracker                       0x0000000106f97cef _TToFC13FlightTracker20StatusViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 79
    6   UIKit                               0x0000000109b5e393 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1293
    7   UIKit                               0x0000000109b5e4d4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
    8   UIKit                               0x0000000109a99331 _applyBlockToCFArrayCopiedToStack + 314
    9   UIKit                               0x0000000109a991ab _afterCACommitHandler + 516
    10  CoreFoundation                      0x000000010937bdc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    11  CoreFoundation                      0x000000010937bd20 __CFRunLoopDoObservers + 368
    12  CoreFoundation                      0x0000000109371b53 __CFRunLoopRun + 1123
    13  CoreFoundation                      0x0000000109371486 CFRunLoopRunSpecific + 470
    14  GraphicsServices                    0x000000010b1ba9f0 GSEventRunModal + 161
    15  UIKit                               0x0000000109a76420 UIApplicationMain + 1282
    16  FlightTracker                       0x0000000106fac07e top_level_code + 78
    17  FlightTracker                       0x0000000106fac0ba main + 42
    18  libdyld.dylib                       0x000000010bdc5145 start + 1
    19  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我是否正确连接了故事板以使用此方法?

根据您 post 的照片,您正在设置 StoryboardID 调用 DistanceID。这与我们正在谈论的 segue identifier 完全不同。

因此,选择 viewControllers 之间的 segue 并将标识符更改为 DistanceID。这是正确的标识符。