视图内变量未更新

问题描述 投票:1回答:1

由于某些原因,变量Tag不会被更新。当运行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
    }
}
swift xcode storyboard
1个回答
1
投票

从这样的标签栏设置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 
}
© www.soinside.com 2019 - 2024. All rights reserved.