O. Boujaouane O. Boujaouane - 7 months ago 9
Swift Question

How to start animation of UIActivityIndicatorin in tableViewCell with Swift?

hope you are well.

I am trying to activate an UIActivityIndicator on specific cell of my tableview. I want to hide labels, images, buttons and show other elements instead of. One of these elements is an UIActivityIndicator which appears but doesn't animate :(

Here the code used :

func showProgressViewInCell(path: NSIndexPath) {
let cell = self.toursUITableView.cellForRowAtIndexPath(path) as! ToursTableViewCell;

// stop userInteraction
cell.userInteractionEnabled = false;

// hide elements
cell.downloadTourButton.hidden = true;
cell.descriptionLabel.hidden = true;
cell.typeOfTourLabel.hidden = true;
cell.typeOfTourImage.hidden = true;
cell.distanceOfTourLabel.hidden = true;
cell.distanceOfTourImage.hidden = true;
cell.durationOfTourLabel.hidden = true;
cell.durationOftourImage.hidden = true;
// show progressbar, percent, activityIndicator and updateLabel
cell.percentLabel.hidden = false;
cell.downloadTourProgressView.hidden = false;
cell.updateLabelProgressBar.hidden = false;
// downloadInProgressActivityIndicator uses option hides when stopped
cell.downloadInProgressActivityIndicator.hidden = false;
cell.downloadInProgressActivityIndicator.startAnimating();

// reload data of tableview
self.toursUITableView.beginUpdates();
self.toursUITableView.reloadData();
self.toursUITableView.endUpdates();
}


Here the configuration on InterfaceBuilder of my UIActivityIndicator :

configuration of UIActivityIndicatorView on Interface Builder

This didn't worked for me : http://stackoverflow.com/a/29494991/6188918

In advance thank you for help.

Answer

Some time ago I made an app which displayed activity indicator inside a cell. I did it by calling startAnimating() inside of cellForRowAtIndexPath method of data source. Try this.