How to set activity indicator for a view when Click the table cell

前端 未结 3 618
醉酒成梦
醉酒成梦 2021-01-29 12:00

I am developing one iPad application using story board.In my view controller one table is set as the left side and one more view is set as the right side.I need to set one activ

相关标签:
3条回答
  • 2021-01-29 12:45

    In didSelectRowAtIndexPath method you could make a call to below function:-

    -(void)setActivityIndcator:(UIView *)view
    {
      transparentView = [[UIView alloc] init];
      transparentView.frame = view.frame;  //Provide frame of right side view.
      transparentView.alpha = 0.5;   //To provide transparent look and feel.
    
      activityInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    
      activityInd.frame = CGRectMake(transparentView.frame.size.width/2, transparentView.frame.size.height/2, 50, 50);  //Change as you want it to be
    
      [transparentView addSubview:activityInd];
    
      [activityInd startAnimating];
    
      [self performSelector:@selector(stopIndicator) withObject:self afterDelay:1];
    }
    
    -(void)stopIndicator  //This method will be called after delay and would remove view and activityInd
    {
      [activityInd stopAnimating];
    
      [activityInd removeFromSuperview];
      [transparentView removeFromSuperview];
    }
    

    Also you could create a subclass of it and use it in any viewcontroller by creating it's object. That why u don't need to write down all function everytime.

    0 讨论(0)
  • 2021-01-29 13:01

    Use the delegate method didSelectRowAtIndexPath of TableView and write the following code into it

    UIActivityIndicatorView *activity = 
    [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activity.frame = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 50, 50);
    [self.view addSubview:activity];
    [activity startAnimating];
    

    Stope this when your work is done and remove it from the view

    0 讨论(0)
  • 2021-01-29 13:07

    use this in this method didSelectRowAtIndexPath

    UIActivityIndicatorView *activityView = 
    [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityView.frame = CGRectMake(120, 230, 50, 50);
    [self.view addSubview:activityView];
    
    0 讨论(0)
提交回复
热议问题