我正在尝试通过 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 确实存在,并且它的标识符设置正确(见下面的屏幕截图)。
这是怎么回事,我该如何解决这个问题?
最佳答案
我相信这就是您要查找的内容,您必须从当前所在的 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/