"Has no segue with identifier" 只有在 `tableView (_: didSelectRowAt:)` 上调用 performSegue 时才会出现错误
"Has no segue with identifier" error occurs only when performSegue is called on `tableView (_: didSelectRowAt:)`
我整天都在努力修复 "has no segue with identifier" 错误,但卡住了。
错误信息:
SegueTest[41862:1585831] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<SegueTest.TableViewController: 0x7feed6510260>) has no segue with identifier 'tableToCollectionSegue''
*** First throw call stack:
相关文件出现错误:
请在 GitHub 上查看我的 Main.storyboard
。
Capture of segue configuration for ViewController ( Working)
Capture of segue configuration for TableViewController (❌ Getting error)
环境:
- macOS 莫哈韦沙漠 10.14.2
- Xcode 10.1
- Swift 4.2
我在Main.storyboard中做了什么:
已创建 UINavigationController
作为初始视图控制器并连接到 RootViewController
作为根视图控制器
创建从 RootViewController
打开的 UINavigationController
作为模态视图
将 Open Modal
按钮与模式 UINavigationController
连接起来,并将其命名为 navigationSegue
创建 ViewController
、TableViewController
和 CollectionViewController
将模式 UINavigationController
与 ViewController
作为根视图控制器连接
将 ViewController
与 TableViewController
连接为名为 viewToTableSegue
的触发转场(手动)
将 TableViewController
与 CollectionViewController
连接为名为 tableToCollectionSegue
的触发转场(手动)
将 ViewController
上的 Next
按钮连接到 ViewController.swift
中声明的 @IBAction func didTapNext(_ sender: Any)
错误是怎么产生的:
当我在 ViewController.swift
中调用 performSegue(withIdentifier:sender:)
时,它起作用了。
(Segue capture)
// Go to TableViewController
@IBAction func didTapNext(_ sender: Any) {
// Working
self.performSegue(withIdentifier: "viewToTableSegue", sender: nil)
}
当我在TableViewController.swift
中调用performSegue(withIdentifier:sender:)
时,出现了错误。
(Segue capture)
override func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
self.tableView.deselectRow(at: indexPath, animated: true)
// ❌ The segue `tableToCollectionSegue` is connected
// from `TableViewController` to `UICollectionViewController`,
// but got error.
//
// *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
// reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''
self.performSegue(withIdentifier: "tableToCollectionSegue", sender: nil)
// ❌ The segue `tableToCollectionSegue` is not connected
// from `UINavigationController` to `UICollectionViewController`.
// This error is expected.
//
// *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
// reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''
// self.navigationController?.performSegue(withIdentifier: "tableToCollectionSegue", sender: self)
}
我阅读的内容:
- performSegueWithIdentifier produce no segue with identifier error
- Segue Error : ViewController has no segue with identifier
- 还有更多
我试过的:
- 确保正确指定并实际连接了 segue 标识符
- 重置所有模拟器设置和内容
- 清理 Xcode 构建文件夹和
~/Library/Developer/Xcode/DerivedData/
目录
- 重命名故事板
- 重启并重建Xcode项目
- 重启Mac
从 TableViewController
中删除以下行:
required public init?(coder aDecoder: NSCoder) {
super.init(style: .plain)
}
我整天都在努力修复 "has no segue with identifier" 错误,但卡住了。
错误信息:
SegueTest[41862:1585831] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<SegueTest.TableViewController: 0x7feed6510260>) has no segue with identifier 'tableToCollectionSegue''
*** First throw call stack:
相关文件出现错误:
请在 GitHub 上查看我的 Main.storyboard
。
Capture of segue configuration for ViewController ( Working)
Capture of segue configuration for TableViewController (❌ Getting error)
环境:
- macOS 莫哈韦沙漠 10.14.2
- Xcode 10.1
- Swift 4.2
我在Main.storyboard中做了什么:
已创建
UINavigationController
作为初始视图控制器并连接到RootViewController
作为根视图控制器创建从
RootViewController
打开的UINavigationController
作为模态视图将
Open Modal
按钮与模式UINavigationController
连接起来,并将其命名为navigationSegue
创建
ViewController
、TableViewController
和CollectionViewController
将模式
UINavigationController
与ViewController
作为根视图控制器连接将
ViewController
与TableViewController
连接为名为viewToTableSegue
的触发转场(手动)
将
TableViewController
与CollectionViewController
连接为名为tableToCollectionSegue
的触发转场(手动)
将
ViewController
上的Next
按钮连接到ViewController.swift
中声明的
@IBAction func didTapNext(_ sender: Any)
错误是怎么产生的:
当我在 ViewController.swift
中调用 performSegue(withIdentifier:sender:)
时,它起作用了。
(Segue capture)
// Go to TableViewController
@IBAction func didTapNext(_ sender: Any) {
// Working
self.performSegue(withIdentifier: "viewToTableSegue", sender: nil)
}
当我在TableViewController.swift
中调用performSegue(withIdentifier:sender:)
时,出现了错误。
(Segue capture)
override func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
self.tableView.deselectRow(at: indexPath, animated: true)
// ❌ The segue `tableToCollectionSegue` is connected
// from `TableViewController` to `UICollectionViewController`,
// but got error.
//
// *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
// reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''
self.performSegue(withIdentifier: "tableToCollectionSegue", sender: nil)
// ❌ The segue `tableToCollectionSegue` is not connected
// from `UINavigationController` to `UICollectionViewController`.
// This error is expected.
//
// *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
// reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''
// self.navigationController?.performSegue(withIdentifier: "tableToCollectionSegue", sender: self)
}
我阅读的内容:
- performSegueWithIdentifier produce no segue with identifier error
- Segue Error : ViewController has no segue with identifier
- 还有更多
我试过的:
- 确保正确指定并实际连接了 segue 标识符
- 重置所有模拟器设置和内容
- 清理 Xcode 构建文件夹和
~/Library/Developer/Xcode/DerivedData/
目录 - 重命名故事板
- 重启并重建Xcode项目
- 重启Mac
从 TableViewController
中删除以下行:
required public init?(coder aDecoder: NSCoder) {
super.init(style: .plain)
}