【发布时间】:2015-10-22 14:01:56
【问题描述】:
我想在每个单元格中创建一个带有文本字段的表格视图,
我在 swift 文件中有一个自定义类:
import UIKit
public class TextInputTableViewCell: UITableViewCell{
@IBOutlet weak var textField: UITextField!
public func configure(#text: String?, placeholder: String) {
textField.text = text
textField.placeholder = placeholder
textField.accessibilityValue = text
textField.accessibilityLabel = placeholder
}
}
然后在我的 ViewController 我有
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("TextInputCell") as! TextInputTableViewCell
cell.configure(text: "", placeholder: "Enter some text!")
text = cell.textField.text
return cell
}
效果很好:
但是当用户在文本字段中输入文本并按下按钮时,我想将每个文本字段的字符串存储在一个数组中。 我试过了
text = cell.textField.text
println(text)
但是如果它是空的,它不会打印任何东西
我怎样才能让它工作?
【问题讨论】:
标签: ios swift uitableview uitextfield cell