接收者没有标识符swift 2的segue

时间:2016-02-09 19:56:49

标签: ios swift segue

我试图通过segue将值从Realm传递到另一个viewcontroller。问题是它崩溃了错误:收件人没有带标识符的segue。我尝试过其他方式,准备不同,但它不如这个好。

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

发生了什么,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我相信这就是你要找的东西,你必须从你当前所在的视图控制器调用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?
}