I'm using the ToastView class from this answer, but I experience the same issue with an activity indicator. I have ToastViews throughout the app but have no qualms switching to an indicator if it will work
My app has a tableview that presents options. After an option is selected, it needs to load a lot of information about the option, like so
class TableController : UITableViewController
{
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = (indexPath as NSIndexPath).row
super.performSegue(withIdentifier: "cellSelectedSegue", sender: self)
}
}
class cellSelectionView : UIViewController
{
override func viewDidLoad() {
super.viewDidLoad()
if let data = parser.getData(...){
// data processing
}
}
}
I'd like to let the user know a loading operation is taking place when they pick a cell. Otherwise a cell gets selected, takes on the cell-selected color, and the app sits still for a second before the segue takes place.
To do so, I've tried
// In the tableview:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Solution 1: ToastView.showInParent(parentView: self.view, text: "ayy lmao", duration: 1.0)
// Solution 2: indicator.startAnimating()
index = (indexPath as NSIndexPath).row
super.performSegue(withIdentifier: "cellSelectedSegue", sender: self)
}
Neither solution works as the UI event is not fired until the cell selection UI event is complete, which doesn't complete until the data processing has taken place, entirely defeating the point. I've also tried moving the UI calls to willSelectRowAt with no difference. I'd like to know how I can let the user know of a loading task that involves a UI event.
If you're wondering why I don't do the data processing before showing the cells rather than on-selection, it's due to the large amount of processing per row. The tableview would take a very long time to appear if done this way