ios - 接收器没有标识符 swift 2 的 segue

标签 ios swift segue

我正在尝试通过 segue 将值从 Realm 传递到另一个 View Controller 。问题是它因错误而崩溃:Reciever has no segue with identifier。我尝试了其他方式,prepareforsegue,但效果不如这个。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let lektire = datasource[indexPath.row]
    let destinationVC = DetaljiViewController()
    destinationVC.programVar = lektire.ime
    destinationVC.performSegueWithIdentifier("oLektiri", sender: self)
}

但是,我的 segue 确实存在,并且它的标识符设置正确(见下面的屏幕截图)。

Here is the screenshot of segue

这是怎么回事,我该如何解决这个问题?

最佳答案

我相信这就是您要查找的内容,您必须从当前所在的 View Controller 调用 performSegueWithIdentifier 并将发送者设置为 indexPath,或者您可以将其设置为数据源项。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
   self.performSegueWithIdentifier("oLektiri", sender: indexPath)

   // Another WAY
   self.performSegueWithIdentifier("oLektiri", sender: datasource[indexPath.row])
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier == "oLektiri") {
       let indexPath = sender as! NSIndexPath
       let toViewController = segue.destinationViewController as? NextViewController
       let lektire = datasource[indexPath.row]
       toViewController?.selectedObject = lektire
    }

    // Another WAY
    if(segue.identifier == "oLektiri") {
       let lektire = sender as? lektireTYPE
       let toViewController = segue.destinationViewController as? NextViewController
       toViewController?.selectedObject = lektire
    }
}

// An example of what the next view controller should look like
class NextViewController: UIViewController {
    var selectedObject: ObjectType?
}

关于ios - 接收器没有标识符 swift 2 的 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301040/

相关文章:

javascript - 具有 WebView 和 native View 的混合应用程序的优缺点是什么?

ios - 使用自定义相机覆盖 View 时底部的黑色 View (UIImagePickerController)

swift - 从函数内触发按钮是否会在堆栈上留下一些东西?

ios - Swift 2.2 - 记事本应用程序,将单独的 textView 关联到单元格而不添加 ViewController

ios - 使用 Storyboard,如何执行反向转场以返回到上一个屏幕?

objective-c - 使用触摸移动事件移动 CALayer

ios - 在 Swift 中带有变量的 NSLocalizedString

Swift 3 : press outside searchBar, 搜索被自动删除

swift - 如何从 JSON 加载 tableView 数据

ios - UISplitViewController:如何从 Detail 返回到 Master