IOS: ActivityIndicator over UITableView… How to?

后端 未结 5 1412
广开言路
广开言路 2020-12-31 03:19

i want display an activity indicator over a uitableview while it\'s loading data (in another thread). So in the ViewDidLoad method of the UITableViewController:



        
5条回答
  •  醉梦人生
    2020-12-31 03:27

    [iOS 5 +]
    If you just want to show the activityWheel without an additional parentview, you can also add the activityWheel straight to the tableView and calculate the y value for the frame using the tableViews contentOffset:

    @interface MyTableViewController ()
    @property (nonatomic, strong) UIActivityIndicatorView *activityView;
    @end
    
    // ....
    
    - (void) showActivityView {
        if (self.activityView==nil) {
            self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
            [self.tableView addSubview:self.activityView];
            self.activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
            self.activityView.hidesWhenStopped = YES;
            // additional setup...
            // self.activityView.color = [UIColor redColor]; 
        }
        // Center 
        CGFloat x = UIScreen.mainScreen.applicationFrame.size.width/2;
        CGFloat y = UIScreen.mainScreen.applicationFrame.size.height/2;
        // Offset. If tableView has been scrolled
        CGFloat yOffset = self.tableView.contentOffset.y;
        self.activityView.frame = CGRectMake(x, y + yOffset, 0, 0);
    
        self.activityView.hidden = NO;
        [self.activityView startAnimating];
    }
    
    - (void) hideActivityView {
        [self.activityView stopAnimating];
    }
    

    If the activityView doesn't show up immediately (or never), refer to zirinisp's answer or do the heavy work in the background.

提交回复
热议问题