我有一个自定义单元格,其中export function HttpLoaderFactory(httpClient: HttpClient) {
return new TranslateHttpLoader(httpClient,"./assets/i18n/", ".json");
}
为子视图。我想检查这个UITextField
是否为空。
有没有办法做到这一点,还是我需要实现一个传递给ViewController的协议?
UITextField
class TitleCell: UITableViewCell {
var titleTextField = UITextField()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
contentView.addSubview(titleTextField)
}
如果titleTextField为空或者没有启用barbuttonItem,我已经实现了一个传递bool值的小协议。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let titleCell = tableView.dequeueReusableCell(withIdentifier: titleCellIdentifier) as! TitleCell
let categoryCell = tableView.dequeueReusableCell(withIdentifier: categoryCellIdentifier)!
switch createEventSections[indexPath.section].items[indexPath.row] {
case .Title:
return titleCell
case .Category:
return categoryCell
}
}
protocol TitleTextFieldDelegate {
func titleTextFieldIsEmpty(isEmpty: Bool)
}
class TitleCell: UITableViewCell {
var titleTextField = UITextField()
var titleTextFieldEmpty: Bool = true
var delegate: TitleTextFieldDelegate?
titleTextField.addTarget(self, action: #selector(titleTextFielddidChangeInput), for: .editingChanged)
@objc func titleTextFielddidChangeInput(textField: UITextField) {
if (titleTextField.text?.isEmpty)! {
titleTextFieldEmpty = true
} else {
titleTextFieldEmpty = false
}
}