2017-03-19 12 views
0

既存のObjective-Cアプリを更新しています。スウィフト - コントローラー間を移動した後に表が空になる

構造があります: AppDelegate - mainBackgroundViewを作成し、私は一つの "タブ" HistoryViewControllerに持ってUITabBarController

でサブビューを追加:

@objc class HistoryViewController: UIViewController { 

    override func viewDidLoad() { 
    super.viewDidLoad() 
    let historyTableViewController = HistoryTableViewController()   
    self.view.addSubview(historyTableViewController.view) 
    } 

} 

そしてHistoryTableViewController:

import UIKit 

@objc class HistoryTableViewController: UITableViewController { 

// Mark: properties 

var historyCalls = [HistoryItem]() 

// Mark: private methods 
private func loadSimpleHistory() { 
    let hist1 = HistoryItem(personName: "Test", bottomLine: "text", date: "10:47") 
    let hist2 = HistoryItem(personName: "Test 2", bottomLine: "text", date: "10:47") 
    let hist3 = HistoryItem(personName: "Test 3", bottomLine: "text", date: "10:47") 
      historyCalls += [hist1, hist2, hist3] 
} 




override func viewDidLoad() { 
    super.viewDidLoad() 

    self.loadSimpleHistory() 

    self.tableView.register(UINib(nibName: "HistoryCallTableViewCell", bundle: nil), forCellReuseIdentifier: "HistoryCallTableViewCell") 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSections(in tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return historyCalls.count 
} 


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "HistoryCallTableViewCell", for: indexPath) as? HistoryCallTableViewCell else { 
     fatalError("Coulnd't parse table cell!") 
    } 

    let historyItem = historyCalls[indexPath.row] 

    cell.personName.text = historyItem.personName 
    cell.bottomLine.text = historyItem.bottomLine 
    cell.date.text = historyItem.date 


    return cell 
} 

} 

初めてHistoryViewControllerでナビゲーションタブを開くと、テーブルaデータと一緒に。私がテーブルをクリックするか、またはnavTabを切り替えてから戻ると、テーブルはもう存在しません。

別のアプリに切り替えてから戻ると、もう一度テーブルが表示されます。

これを修正するにはどうすればよいですか?

はあなたにviewwillappearで

+0

リロードテーブルビューは、してください –

+0

表示され、それを行う方法? – David

+0

チェック 'adarshu'答えがない場合は私に教えてください –

答えて

0

コールデータの方法を感謝し、テーブルをリロード..ビューに

override func viewWillAppear() { 
    super.viewWillAppear() 
    self.loadSimpleHistory() 
    self.tableview.reloadData() 
    } 
+0

私はそれをHistoryTableViewControllerに入れて、HistoryViewControllerのフォームviewWillAppearを呼び出す必要がありました。htvc.viewWillAppear - UITableViewのviewWillAppearは自動的に呼び出されません – David

関連する問題