【发布时间】:2016-04-26 22:43:40
【问题描述】:
我有一个 TableViewController、TableViewCell 和一个 ViewController。我在 TableViewCell 中有一个按钮,我想向 ViewController 展示presentViewController(但 ViewController 在情节提要上没有视图)。我尝试使用:
@IBAction func playVideo(sender: AnyObject) {
let vc = ViewController()
self.presentViewController(vc, animated: true, completion: nil)
}
错误:TableViewCell 类型的值没有成员 presentViewController
然后,我尝试了
self.window?.rootViewController!.presentViewController(vc, animated: true, completion: nil)
错误:警告:尝试显示不在窗口层次结构中的视图!
我做错了什么?为了从 TableViewCell 中展示 ViewController,我应该怎么做?另外,如何将数据从 TableViewCell 传递给新的呈现 VC?
更新:
protocol TableViewCellDelegate
{
buttonDidClicked(result: Int)
}
class TableViewCell: UITableViewCell {
@IBAction func play(sender: AnyObject) {
if let id = self.item?["id"].int {
self.delegate?.buttonDidClicked(id)
}
}
}
----------------------------------------
// in TableViewController
var delegate: TableViewCellDelegate?
func buttonDidClicked(result: Int) {
let vc = ViewController()
self.presentViewController(vc, animated: true, completion: nil)
}
我收到错误:不鼓励在分离的视图控制器上显示视图控制器
(请注意,我在 TableView 后面有一个 NavBar 和 TabBar 链。)
我也试过
self.parentViewController!.presentViewController(vc, animated: true, completion: nil)
同样的错误。
也试过了,
self.view.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
同样的错误
【问题讨论】:
-
该按钮是否意味着辅助(例如,附件视图)选择?
标签: ios swift uitableview tableview tableviewcell