Skip to content

Instantly share code, notes, and snippets.

@iolate
Created April 29, 2013 05:55
Show Gist options
  • Save iolate/5479930 to your computer and use it in GitHub Desktop.
Save iolate/5479930 to your computer and use it in GitHub Desktop.
UIActivityIndicator on UITableView header. ( >= iOS6 )
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITableViewHeaderFooterView *sectionHeaderView = nil;
if (section == 1) {
sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerIndicatorView"];
if (sectionHeaderView == nil) {
sectionHeaderView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"headerIndicatorView"];
}
float indicatorSize = 21.0f;
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(120, 7, indicatorSize, indicatorSize)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[sectionHeaderView.contentView addSubview:activityIndicator];
[activityIndicator startAnimating];
}else{
sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"defaultHeader"];
if (sectionHeaderView == nil) {
sectionHeaderView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"defaultHeader"];
}
}
return sectionHeaderView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment