【发布时间】:2015-12-16 06:35:37
【问题描述】:
如何将文本添加到tableViewCell?我拖了一个textfield和button,并在它们下面添加,设置tableView和tableviewCell。单元格的标识符是“Cell”。这是我到目前为止制作的代码。理想情况下,我想将在textfield 中输入的文本添加到单元格中,例如,如果我添加我的名字,它将被添加,如果下一个人添加她的名字,她的名字也会出现在单元格上。
@IBOutlet weak var myTableView: UITableView!
@IBOutlet weak var textField: UITextField!
var stringArray = [String]()
@IBOutlet weak var AddBUtton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
textField.delegate = self
}
func textFieldDidBeginEditing(textField: UITextField) {
}
func textFieldDidEndEditing(textField: UITextField) {
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
return true
}
func textFieldShouldClear(textField: UITextField) -> Bool {
return true
}
func textFieldShouldEndEditing(textField: UITextField) -> Bool {
return true
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = self.myTableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! UITableViewCell
return cell
}
【问题讨论】:
标签: ios swift uitableview uitextfield