我有一个 tableView
有 7 行,每一行是一个不同的 Action 。当用户点击一行时, View Controller 将显示为弹出窗口,并显示一个文本字段,供用户添加注释。然后我想将此注释保存到 Parse,但我需要用它保存 passedChildID,因此它 (passedChildID) 需要从 tableviewcontroller
传递.我在我的应用程序的其他区域中使用了此功能 tableView
到另一个tableView
但由于某种原因,它无法与弹出窗口一起使用。
以下代码在SingleChildViewTableViewController
中.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "childToNote" {
let popoverViewController = segue.destinationViewController
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
popoverViewController.popoverPresentationController!.delegate = self
let noteActionViewController = segue.destinationViewController as! actionNoteViewController
if let indexPath = tableView.indexPathForCell(sender as! UITableViewCell) {
noteActionViewController.passedChildID = passedChildID
}
}
if segue.identifier == "childToItemNeeded" {
//other stuff
}
}
它构建并运行良好,但是当我点击该特定行时,出现以下错误。
Could not cast value of type '<<app_name>>.SingleChildTableViewController' (0x10e1bef60) to 'UITableViewCell' (0x110bca128).
我试过移动 let noteActionViewController...
let popoverViewController
上方的代码认为前者永远不会运行,但这并没有改变任何事情。
segue 的执行方式如下(以防有任何差异)。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
performSegueWithIdentifier("childToNote", sender: self)
}
}
我很困惑,因为这段代码在我的应用程序的其他地方都有效。
最佳答案
看起来你的问题出在这一行
indexPathForCell(sender as! UITableViewCell)
在这种情况下,你告诉它发送者是自己,它是一个 UIViewController
performSegueWithIdentifier("childToNote", sender: self)
然后您在 indexPathForCell
行中告知将其转换为 UITableViewCell 但其类型为 SingleChildTableViewController
。所以将发件人更改为 UITableViewCell
关于ios - 将变量 (Int) 传递给 View 控件 (Popover),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34386614/