How can i add a activity indicator below the UITableView?

后端 未结 4 1465
自闭症患者
自闭症患者 2020-12-28 17:22

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

相关标签:
4条回答
  • 2020-12-28 17:44

    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.

    0 讨论(0)
  • 2020-12-28 17:49

    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.

    0 讨论(0)
  • 2020-12-28 18:01

    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.

    0 讨论(0)
  • 2020-12-28 18:02

    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
    
    0 讨论(0)
提交回复
热议问题