【发布时间】:2020-05-23 19:57:27
【问题描述】:
我创建了一个表格和一个文本字段。每次用户在文本框中写东西时,我希望表格创建一个新单元格。我有这样的代码。我为名称创建了一个数组并尝试用它填充单元格,但到目前为止还没有结果。
var playerName = [String]()
@IBAction func addPlayerNameTextFieldAction(_ sender:UITextField)
{
let name = addplayerTextFiedOutlet.text!
playerName.append(name)
addplayerTextFiedOutlet.resignFirstResponder()
playerListTableView.reloadData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = playerListTableView.dequeueReusableCell(withIdentifier: idCell, for:indexPath) as! PlayerListTableViewCell
cell.playerNameLabel.text = playerName[indexPath.row]
return cell
}
【问题讨论】:
-
no result是什么意思?
-
我在文本字段中输入单词,按回车键,没有任何操作。连键盘都没有消失。
-
是否调用了该操作?请使用调试器。
-
点击文本字段后,出现一个键盘,我可以输入文本,但接下来没有任何反应。我试图将数组输出为字符串,但它没有输出任何内容
标签: ios arrays swift uitableview uitextfield