I have UITableView 开发者_开发知识库with a navigationBar at the top. I have a refresh button in the right of the navigationBar.
When clicking on the refresh button, i need to start an activity indicator, refresh the table and stop the activity indicator.
-(void)refreshClicked{
[spinner startAnimating]; //UIActivityIndicatorView object
[appDelegate readJSONData]; //this is the method which populates the array
//for displaying in the tableview
}
I want know how to refresh the table after populating the array and then how to stop the activity indicator.
thanks :)
Refresh table:
[tableView reloadData];
Stop activity indicator:
[spinner stopAnimating];
-----EDIT-----
From your comments, I can gather that you want to smoothly fade the spinner away and reload the tableview.
For the tableview:
You can reload sections of the tableview with a nice fade animation using the following code:
[tableView reloadSections:(NSIndexSet *)sections withRowAnimation:UITableViewRowAnimationFade];
Your indexset contains all the sections you want to reload and you DO have other options for the reload animation. Look here: UITableViewRowAnimations
To create an NSIndexSet see this link
As for your spinner, you could fade it to alpha zero before calling stopAnimating by doing this:
-(void)fadeSpinner
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(stopAnimation)];
spinner.alpha = 0;
[UIView commitAnimations];
}
- (void)stopAnimation
{
[spinner stopAnimating];
}
reload data:
[yourTableviewController.tableView reloadData];
and if you need to relayout:
[yourTableviewController.tableView setNeedsDisplay];
[yourTableviewController.tableView setNeedsLayout];
精彩评论