变量未在视图内更新

Variable not updating inside the view

由于某种原因,变量标签没有被更新。当 SelectedSauce 为 运行 时,它应该 运行 函数,然后更新变量。但是一旦离开该功能,它就不会被更新。我不确定这有什么问题。当我改变视图时,我将一个变量从以前的视图传递给 selectedsauce 到这里。我不确定它是否有帮助或改变了什么,但我正在使用领域数据库

class InfoUITableViewController: UITableViewController {


    var SelectedSauce: Sauce? {
        didSet {
            print("1st")
            AcquireData()
        }
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        print("3rd")
        print("Loaded")

        tableView.register(UINib(nibName: "DetailsTableViewCell", bundle: nil), forCellReuseIdentifier: "Super")
        tableView.dataSource = self

        //Returns nill even though i changed the variable in acquiredata
        print(Tags)
    }

    let realm = try! Realm()

    var Tags: List<NiceTags>?

    //MARK: - Data Manipulation

    func AcquireData() {
        print("2nd")
        if let Sauce = SelectedSauce {
            Tags = Sauce.tags
            //            print(Tags)
        }
            self.Tags = self.SelectedSauce?.tags
            print(self.Tags)
        tableView.reloadData()
    }


    // MARK: - Table view data source

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("4th")

        let cell = tableView.dequeueReusableCell(withIdentifier: "Super", for: indexPath) as! DetailsTableViewCell

        //This isn't running, and just uses the default text inside the label
        if let TheTags = Tags?[indexPath.row] {
            cell.Inflabel.text = TheTags.tags
        }


        return cell
    }




    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of row
        print("5th")
        //Returns 7 because tags is still nill
        return Tags?.count ?? 7
    }
}

像这样从标签栏设置 SelectedSauce

override func viewDidLoad() { 
super.viewDidLoad() 
swipeAnimatedTransitioning?.animationType = SwipeAnimationType.sideBySide 
// isCyclingEnabled = true 
// Do any additional setup after loading the view. 
print("order") 
let first_vc = self.viewControllers?.first as! DetailViewController 
let last_vc = self.viewControllers?.last as! InfoUITableViewController 
first_vc.SelectedSauce = SelectedSauce 
last_vc.SelectedSauce = SelectedSauce 
}