【发布时间】:2017-01-07 16:11:31
【问题描述】:
我在自定义 UITableViewCell 中有一个 UITextField。
当点击自定义单元格中的 UITextField 时,我需要切换到新的视图控制器。
尝试的解决方案
我尝试在 CustomTableViewCell 类中使用
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
print("Text Field Tapped")
return false
}
但是这不起作用,因为 performSegue 是一个 ViewController 函数。然后我尝试了
func someAction() {
performSegue(withIdentifier: "identifier", sender: self)
}
在 MyViewController 类中,但这也不起作用(不知道为什么)。这是我的两个类的样子:
MyViewController(持有 UITableView)
import UIKit
class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:SearchTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "cell") as! SearchTableViewCell
return cell
}
}
CustomTableViewCell
import UIKit
class CustomTableViewCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var someTextField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
self.someTextField.delegate = self
}
}
非常感谢您的聪明人可以提供的任何帮助:)
【问题讨论】: