In my application i want to add activity indicator under UItableview where tableview will scroll but i do not know how can i add activity indicator over there.
To el
One more way to add activity indicator. Check if your data displayed is not equals to the total count of data. Then you add one extra cell and Add "View More" button. When i click on the view more the hide that button and add activity indicator in that cell. And when process is done then reload the table view.
Thanks.
This is how I've done it:
UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
[spinner startAnimating];
spinner.frame = CGRectMake(0, 0, 320, 44);
self.tableView.tableFooterView = spinner;
Then you just set tableFooterView
to nil
to remove it.
Note:
44, btw, is the default height of a UITableViewCell
when using UITableViewStylePlain
.
It's 45 for UITableViewStyleGrouped
.
The best way to add activity indicator is at footer of tableview.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = [[[UIView alloc] init]autorelease];
[headerView setBackgroundColor:[UIColor clearColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Load More" forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);
[headerView addSubview:button];
[headerLabel release];
return headerView;
}
Add a button to the footerView and set action to button (as you needed). This how app store tableview works. On clicking button fetch some more data add to table array scroll the table without animation.
Swift Update :-
let pagingSpinner = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
pagingSpinner.startAnimating()
pagingSpinner.color = UIColor(red: 22.0/255.0, green: 106.0/255.0, blue: 176.0/255.0, alpha: 1.0)
pagingSpinner.hidesWhenStopped = true
tableView.tableFooterView = pagingSpinner