我正在实现一个UITableViewController,前两个中有3个部分分别包含2个和1个文本字段。我在访问文本字段中的文本输入时遇到问题。我不知道如何在iOS swift中解决这个问题请帮忙。
在表格视图控制器
中SELECT
[KEY]
,STUFF((SELECT distinct ', ' + [Code] FROM #tempTable t WHERE t.[KEY]=tt.[KEY] FOR XML PATH('')),1,1,'') AS [Code]
,STUFF((SELECT distinct ', ' + CAST([CreatedDate] AS NVARCHAR(100)) FROM #tempTable t WHERE t.[KEY]=tt.[KEY] FOR XML PATH('')),1,1,'') AS [CreatedDate]
FROM #tempTable tt
Group by KEY
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let gender = Gender(rawValue: indexPath.row)
switch indexPath.section {
case 0:
guard let nameCell = tableView.dequeueReusableCellWithIdentifier("addNameCellID") as? ChildFormViewCell else {
return UITableViewCell()
}
nameCell.firstNameField.text = "" // just in case cells are re-used, this clears the old value
nameCell.firstNameField.tag = indexPath.row
return nameCell
case 1:
self.tableView.rowHeight = 50
guard let dateCell = tableView.dequeueReusableCellWithIdentifier("addDateCellID") as? ChildFormViewCell else {
return UITableViewCell()
}
return dateCell
case 2:
guard let genderCell = tableView.dequeueReusableCellWithIdentifier("addGenderCellID") as? ChildFormViewCell else {
return UITableViewCell()
}
genderCell.genderLabel.text = gender?.nameString()
return genderCell
default:
return UITableViewCell()
}
}
extension AddChildFormTVC: ChildFormViewCellDelegate {
func getFirstName(text: String?) {
print(text)
}
func getLastName(text: String?) {
print(text)
}
func getDateOfBirth(text: String?) {
print(text)
}
func getGender(text: String?) {
print(text)
}
}
答案 0 :(得分:0)
然后尝试:
//This will call back after focus is lost from the input
self.textField.addTarget(self, action: #selector(updateFirstName), forControlEvents: .EditingDidEnd)
//This will call back with every change, i.e. each letter
self.textField.addTarget(self, action: #selector(updateFirstName), forControlEvents: .EditingChanged)
此外,如果self
被添加为目标,则self
表示UITableViewController
。据我所知,一个对象不能是它自己的委托。如果可能的话,那就没有意义了。