你好我试图用一个视图控制器与表视图单元内的一个uibutton连接作为弹出连接。我有一个小的视图控制器与2个按钮,里面应该是我的popover。我在这些单元格内有许多许多单元格和按钮的tableview。当用户点击一个特定的按钮时,我想打开一个带有点击按钮上的锚点的弹出窗口,就像静态内容上的弹出连接的默认行为一样。Swift 3:从动态uitableviewcell中的按钮到uiviewcontroller的popover连接
但随着动态内容,我让我的故事板这个错误打交道时: 无法编译连接...
我不想使用像隐藏的1像素按钮等这样的肮脏的黑客。我试图创建一个自定义的赛格,但它也不是很好。
那么实现这一目标的最佳方法是什么?
这是这个例子中的样子为代码:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CustomTableViewCell
let button = cell.customButton
return cell
}
}
import UIKit
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var customButton: UIButton!
@IBAction func buttonTapped(_ sender: Any) {
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
为什么你想在你的单元内使用uiviewcontroller吗? –
我不想在我的单元格内使用uiviewcontroller。我也没有得到正确的问题 – Kingalione
在代码中显示弹出窗口。您不能使用原型单元格中的视图作为故事板中弹出窗口的锚点视图。 – dan