2017-07-02 43 views

回答

0
  1. 您必须为您的UITableView设置IBOutlet。

  2. 在UIButton的IBAction中,为用于实现tableview单元格的数据结构添加一个值。

  3. 然后调用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() 
    }