Cant Get the activity indicator to show on iPhone app

前端 未结 2 2122
情深已故
情深已故 2021-01-17 02:04

I have a view which is created in IB. inside it I have a scroll view created programmatically. Within the scroll view I connect to a web service and fetch the content and th

2条回答
  •  星月不相逢
    2021-01-17 02:49

    You should do this in you viewDidload

    - (void)viewDidLoad
    {
        //Start Activity Indicator View
        indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        indicatorView.frame = CGRectMake(40.0, 20.0, 60.0, 60.0);
        indicatorView.center = self.view.center;
        [self.view addSubview:indicatorView];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        [indicatorView startAnimating];
    
        [self performSelectorInBackground:@selector(loadscroll) withObject:self];
    }
    

    Note: "performSelectorInBackground" will show you an activity indicator on the view and your loadScroll method will fetch all data from internet and do other work.

    -(void)loadscroll
    {
        //Your Scroll View 
            //Your other Data Manipulation even from internet
            //When data is fetched display it 
           [self removeActivityIndicator]; //To stop activity Indicator       
    }
    
    - (void)removeActivityIndicator
    {
           [indicatorView stopAnimating];
    }
    

提交回复
热议问题