Closed chuninator closed 6 years ago
Try running this whole block of code on main thread.
self.categoriesArray.removeAll()
self.categoriesArray = Array(categories!.makeIterator()) as! [Category]
for category in self.categoriesArray {
let name = category.name
DispatchQueue.main.async {
self.segmentedControl.insertSegment(withTitle: name, at: int)
}
}
@GocePetrovski Hm, no luck... any other ideas? I also tried appending to the array one by one as opposed to makeIterator()
Fixed it. Really nothing to do with the ScrollableSegmentedControl. For some reason even DispatchQueue.main.async {}
wasn't actually executing code on main thread. Used a different function findObjects()
for finding objects synchronously.
func loadCategories() {
let queryForCategories = PFQuery(className: Category.parseClassName())
queryForCategories.whereKey("active", equalTo: true)
do {
let results: [Category] = try queryForCategories.findObjects() as! [Category]
print("These are the results \(results)")
for r in results {
categoriesArray.append(r.name)
self.segmentedControl.insertSegment(withTitle: r.name, at: 0)
}
} catch {
print(error)
}
}
I guess just make sure your results are always being inserted on main thread. UI update so it makes sense. Thank you for the time and mind space.
Aloha,
Running into a problem when I load the needed segments in from an array, as opposed to doing it statically.
This function works and gives the desired output. All 5 show up in the segmentedControl.
Photo:
On the other hand, when making a request from our database, here's what happens. The segments show up individually instead of filling the entire screen with x amount that we need.
Photo:
Any help greatly appreciated. Thank you.