2017-10-13 15 views
0

メインViewControllerを持つスウィフトプログラムと、画面をオーバーレイするポップアップを制御するセカンダリVCを作成しようとしています。このポップアップでは、ログイン資格情報を入力することができます。これは、ViewControllertableViewに表示されます。いけません(別のViewControllerからViewTableをリフレッシュする方法

は、これまでのところ私はコアデータに二次VCに入力した値を保存することができるよ、それはちょうどカントreloadData()関数を参照してくださいので、私は、最初のVCでtableViewためreloadData()にできないんだけど私が迅速に動くようになったので、わからない)。

誰かがこれを行う最善の方法を見つけ出すのに役立つでしょうか?

メインのViewControllerコード:

import UIKit 

class ViewController: UIViewController { 


    @IBOutlet weak var tableView: UITableView! 

    var account = [Account]() 
    @IBAction func onAddAccount(_ sender: Any) { 
     self.tableView.reloadData() 
     print("RELOADED") 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

    } 

    @IBAction func onBlank() { 
     self.tableView.reloadData() 
    } 
} 


extension ViewController: UITableViewDataSource { 
    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return account.count 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil) 
     cell.textLabel?.text = account[indexPath.row].email 
     cell.detailTextLabel?.text = account[indexPath.row].password 
     return cell 
    } 
} 
+0

これは 'UITableViewDelegate'がないためですか? – Amit

答えて

0

私は自分自身迅速に比較的新しいです。しかし、私はあなたが探していると思うのは、Delegateは、データが更新され、更新されたことをメインコントローラに伝えます。また、あなたはデータソースが必要かもしれないようですね?モデル、ビュー、コントローラのアーキテクチャを実装することができます。

関連する問題