简体   繁体   中英

Swift - self.tableview.reloaddata() not working on Master Detail Application

I used xcode's premade Master detail application and built off of that. For the tableview, I am making a json request and storing that into coredata; and trying to populate the table based on that coredata.

The way it works, is that the user logs in and then a request is made for a user's specific team. The resulting title and url are saved into coredata and used to populate the tableview/detail view.

Although the coredata is being updated (printing out the logs), the tableview itself is never being updated. I have tried putting self.tableView.reloadData() in viewDidLoad, viewDidAppear, and viewWillAppear; I have also tried creating a timer that calls the reloadData every .4 seconds (current code) and I never see the table cell's textLabel updated. However, if I tap on a cell, the link that is loaded in the detail view IS updated. So to re-iterate, the coredata is being updated, but the table never updates its label text.

If I stop running the app through xcode and then run it again, then the tableview is populated with the labels; but changing the team/user leads to the same results (the coredata/links are updated and the text labels are not)

My code is definitely not the cleanest/best, just trying to get it to work at the moment.

Here's my MasterViewController.swift: https://gist.github.com/aryanaziz/a9791a82061f156afdb9

EDIT: Found the issue. I was using the self.tableView.beginUpdates() function but was never using the self.tableView.endUpdates() which was causing problems. Removing the beginUpdates() had the tableview behaving like normal.

Found the issue. I was using the self.tableView.beginUpdates() function but was never using the self.tableView.endUpdates() which was causing problems. Removing the beginUpdates() had the tableview behaving like normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM