2017-10-13 3 views
0

ViewController 메인과 화면을 오버레이하는 팝업을 제어하는 ​​보조 VC를 만드는 빠른 프로그램을 만들려고합니다. 이 팝업에서 tableView (기본 ViewController)으로 표시되는 로그인 자격 증명을 입력 할 수 있습니다. 하지해야합니다 (별도의 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입니다. 메인 컨트롤러에 데이터가 업데이트되었고 업데이트 된 것을 알려줍니다. 또한 데이터 소스가 필요할 수도 있습니다. 따라서 모델, 뷰, 컨트롤러 아키텍처를 구현할 수 있습니다.