0
我想知道如何使用UIButton
动作函数来按下按钮,这样每次按下按钮时,都会添加一个UITableView
中的新行。有谁知道如何做到这一点?UIButton在Swift 3中更新UITableView
我想知道如何使用UIButton
动作函数来按下按钮,这样每次按下按钮时,都会添加一个UITableView
中的新行。有谁知道如何做到这一点?UIButton在Swift 3中更新UITableView
您必须为您的UITableView设置IBOutlet。
在UIButton的IBAction中,为用于实现tableview单元格的数据结构添加一个值。
然后调用reloadData()用于实现代码如下出口
即函数,在代码
@IBOutlet weak var table: UITableView!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell?.textLabel = dataStructure[indexPath.row]
return cell
}
对于IBAction为
@IBAction func buttonPressed(_ sender: UIButton)
{
dataStructure.append(someNewValue); // someNewValue is the new Value for the row
table.reloadData()
}