2017-07-02 11 views
0

UIButtonアクション機能を使用して、ボタンを押すたびにUITableViewの新しい行が追加されるようにする方法が不思議です。誰もそれを達成する方法を知っていますか?Swift 3のUITableViewを更新するUIButton

答えて

0
  1. あなたのUITableViewにIBOutletを設定する必要があります。

  2. UIButtonのIBActionで、tableviewのセルを実装するために使用したデータ構造体に値を追加します。

  3. は、コードIBAction

    @IBAction func buttonPressed(_ sender: UIButton) 
        { 
         dataStructure.append(someNewValue); // someNewValue is the new Value for the row 
         table.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 
    } 
    

では、テーブルビューの出口

ためreloadData()関数を呼び出します

関連する問題