This is significantly easier because it doesn't involve any third party stuff (even though MBProgressHUD is a great tool). When I created the cell, I created a UIACtivityIndicatorView and added it as the cell's accessoryView. Later, when a row is pressed, I grab a reference to the cell itself at the appropriate indexPath, and then access its accessoryView property, which is the indicator view. From there you can just tell it to start animating.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.accessoryView = activityIndicator;
}
cell.textLabel.text = _items[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// deselect the row if you want the cell to fade out automatically after tapping
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// get a reference to the cell that the user tapped
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// get the tapped cell's accessory view and cast it as the activity indicator view
UIActivityIndicatorView *activityIndicator = (UIActivityIndicatorView *)cell.accessoryView;
// tell it to start animating
[activityIndicator startAnimating];
}
This results in the following after tapping the first cell:
You'll have to change the code a bit depending on when/how you want to stop the activity indicator from spinning, but without have more information from you this is the best info I can provide. You'll likely want to add the indexPath.row integer to the progressView's tag property, but there's a bit more to that. Hope this helps!
EDIT
Add a tag to the button that's the indexPath of the row, and do something like:
- (void)showProgressViewForButton:(id)sender {
NSInteger tappedCellIndex = sender.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:tappedCellIndex inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *activityIndicator = (UIActivityIndicatorView *)cell.accessoryView;
[activityIndicator startAnimating];
}