ios - 继续错误 : ViewController has no segue with identifier

标签 ios swift

我陷入了非常深的困境。我意识到有很多关于我的错误的 SO 主题,我已经浏览了这些答案的 3-4 页谷歌搜索结果,并尝试了所有解决方案。没有一个有效。

我试过的:

  1. 重置模拟器设置
  2. 清理 Xcode 构建文件
  3. 重命名 Storyboard
  4. 检查确定的 segue 是否拼写错误(数百次)
  5. 重新启动并重建 xCode 项目
  6. 确保 segue 实际上与错误中的 ViewController 相关联。

问题:我从 ViewProjectViewController 转到了 RecordModule。然后我以编程方式向 ViewProjectViewController 的 NavBar 添加了一个栏按钮,因为该导航栏是从以前的 VC 以编程方式制作的。

然后您可以为“item3”..这是我单击以使用 performSegueWithIdentifier 运行函数的按钮。但是当我点击它时,我得到了这个错误:

2016-04-29 12:54:59.098 music[9298:1272742] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<music.ViewProjectViewController: 0x7bead670>) has no segue with identifier 'recMod''
*** First throw call stack:
(
    0   CoreFoundation                      0x00ac3494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x02e9be02 objc_exception_throw + 50
    2   UIKit                               0x01b4971c -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
    3   music                               0x00089ad8 _TFC5music25ViewProjectViewController13openRecModulefPs9AnyObject_T_ + 168
    4   music                               0x00089b4a _TToFC5music25ViewProjectViewController13openRecModulefPs9AnyObject_T_ + 58
    5   libobjc.A.dylib                     0x02eb00b5 -[NSObject performSelector:withObject:withObject:] + 84
    6   UIKit                               0x01977e38 -[UIApplication sendAction:to:from:forEvent:] + 118
    7   UIKit                               0x01e079da -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 179
    8   libobjc.A.dylib                     0x02eb00b5 -[NSObject performSelector:withObject:withObject:] + 84
    9   UIKit                               0x01977e38 -[UIApplication sendAction:to:from:forEvent:] + 118
    10  UIKit                               0x01977db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    11  UIKit                               0x01b1bf3b -[UIControl sendAction:to:forEvent:] + 79
    12  UIKit                               0x01b1c2d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
    13  UIKit                               0x01b1c483 -[UIControl _sendActionsForEvents:withEvent:] + 864
    14  UIKit                               0x01b1b2c1 -[UIControl touchesEnded:withEvent:] + 714
    15  UIKit                               0x019f852e -[UIWindow _sendTouchesForEvent:] + 1095
    16  UIKit                               0x019f95cc -[UIWindow sendEvent:] + 1159
    17  UIKit                               0x0199abe8 -[UIApplication sendEvent:] + 266
    18  UIKit                               0x0196f769 _UIApplicationHandleEventQueue + 7795
    19  CoreFoundation                      0x009d5e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    20  CoreFoundation                      0x009cbaeb __CFRunLoopDoSources0 + 523
    21  CoreFoundation                      0x009caf08 __CFRunLoopRun + 1032
    22  CoreFoundation                      0x009ca846 CFRunLoopRunSpecific + 470
    23  CoreFoundation                      0x009ca65b CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x05d4e664 GSEventRunModal + 192
    25  GraphicsServices                    0x05d4e4a1 GSEventRun + 104
    26  UIKit                               0x01975eb9 UIApplicationMain + 160
    27  music                               0x000a7391 main + 145
    28  libdyld.dylib                       0x040a1a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

这是我的代码(ViewController - Segue 的起点)

class ViewProjectViewController: UITableViewController {




    var selectedProj: Array<String> = []
    var selectedKey: String = ""


    var listItemsTwo = [ListItemTwo]()

    let shareDataTwo = SharedDataTwo.sharedInstance


    override func viewDidLoad() {
        super.viewDidLoad()

        // Setup Left UIBarButton Here
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:  "BackBtn"), style: .Plain, target: self, action: #selector(ViewProjectViewController.backButtonPressed(_:)))


        // Setup Right UIBarButton Here

        var items : Array<UIBarButtonItem> = []


        let item1 = UIBarButtonItem(image: UIImage(named: "SaveBtn"),style: UIBarButtonItemStyle.Plain, target: self, action: #selector(ViewProjectViewController.saveChanges))

        let item2 = UIBarButtonItem(image: UIImage(named:  "EditBtn"), style: .Plain, target: self, action: #selector(ViewProjectViewController.editProject))


        // SEGUE BUTTON NOT WORKING //////////////////////
        let item3 = UIBarButtonItem(title: "Record", style: .Plain, target: self, action: #selector(ViewProjectViewController.openRecModule))
        item3.tintColor = UIColor.redColor()

        items.append(item1)
        items.append(item2)
        items.append(item3)


        self.navigationItem.setRightBarButtonItems(items, animated: true)




        item1.setTitleTextAttributes([
            NSFontAttributeName: UIFont(name: "Aldrich", size: 12.0)!],
                                           forState: UIControlState.Normal)

这是转场代码(ViewProjectViewController)

func openRecModule(sender: AnyObject) {
    self.performSegueWithIdentifier("recMod", sender: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if let destinationVC = segue.destinationViewController as? RecordModule {
        destinationVC.transitioningDelegate = self
    }



}

界面生成器图像 - http://i.imgur.com/klbwdrm.png

ViewProjectViewController 如何出现在屏幕上

MainPanelViewController 将用户定向到 ViewProjectViewController

MainPanelViewController 是一个 UIViewController,其中嵌入了 UITableViewUITableViewCell 的代码如下(这也是 ViewProjectViewController 的转折点)

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let keys = Array(sharedDataThree.c.keys)
        let object = self.sharedDataThree.c[keys[indexPath.row]]

        let newProgramVar = object as! NSArray

        let destinationVC = ViewProjectViewController()

        destinationVC.selectedProj = newProgramVar as! Array<String>
        destinationVC.selectedKey = keys[indexPath.row]

        //performSegueWithIdentifier("viewProject", sender: self)

        var alreadyPushed = false

        if let vc = self.navigationController?.viewControllers {
            for viewController in vc {
                if let viewController = viewController as? ViewProjectViewController {
                    self.navigationController?.popToViewController(viewController, animated: true)
                    print("Push your controller")
                    alreadyPushed = true
                    break
                }
            }
        }
        if alreadyPushed == false {
            self.navigationController?.pushViewController(destinationVC, animated: true)
        }

最佳答案

试试这个:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "recMod" {
        let destinationVC = segue.destinationViewController as? RecordModule 
        destinationVC.transitioningDelegate = self
    }
}

关于ios - 继续错误 : ViewController has no segue with identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36946528/

相关文章:

ios - GameplayKit > 让代理在目标跟随路径后停止移动

objective-c - 如何在标签栏应用程序的 iOS 6 GM 中使旋转正常工作?

objective-c - 单例获取核心数据,在 [fetchedResultsController performFetch :&error] 上崩溃

ios - 更改 UIBarButtonItem 文本字体大小和颜色

swift - 将 for 循环语句重构为 swift 3.0

ios - Paypal 集成 swift iOS

swift - 我可以将字符串转换为 SINCall 吗?

ios - 如何关闭 iOS 版 VLC 媒体播放器的硬件解码选项

Swift 创建一个协议(protocol),但它不起作用

ios - Google SDK iOS - sign() 方法完成处理程序