【发布时间】:2016-10-06 16:16:04
【问题描述】:
我有一个子类CustomCell,它继承自我的父类CreateEvent。该子类描述了表格视图单元格的各个单元格,它位于 CreateEvent 视图控制器上。在一个特定的单元格中,我有一个文本字段,它链接到 CustomCell 文件,但是当用户输入文本字段时,我无法从该文本字段中获取值。我也无法通过外部触摸关闭键盘并按返回键,但我主要专注于从文本字段中获取文本。我熟悉在普通的 swift 文件上执行这些功能,但因为这是一个子类,我不知道该怎么做。我尝试过的是使用:
class CustomCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var entranceFeeTextField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
还有:
class CreateEventVC: UIViewController, UITableViewDelegate, UITableViewDataSource, CustomCellDelegate, UITextFieldDelegate {
override func viewDidLoad() {
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: currentCellDescriptor["cellIdentifier"] as! String, for: indexPath) as! CustomCell
cell.entranceFeeTextField.delegate = self
entranceFeeAmount = cell.entranceFeeTextField.text!
}
此代码未运行,我不确定需要运行哪些文本字段委托才能从文本字段中获取文本值。
【问题讨论】:
标签: ios uitableview delegates textfield