Search code examples
iosuiviewuibuttonactivity-indicator

Display activity indicator only after clicking the button


hi I’m trying view the activity indicator by clicking the button. I have tried but i having some issues. If i drag the activity indicator to my storyboard but its visible while running my app i want to display while clicking the button. in my app I’m giving the photo upload option. So if they click the upload button i want to view the activity indicator . ..

this is code i have tired but its not working.

this is my h file where i have implemented the activity indicator and the button..

- (IBAction)click:(id)sender;
 @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner;

this is code which i have used in my m file...

-(void)temp
{
 spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
 spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
 [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
 [self.view addSubview:spinner];
 [spinner startAnimating];
 [spinner release];
}

and im calling this function in my button..

- (IBAction)click:(id)sender {
[self temp];
}

and also im have some other issues i saw the code here the problem is

[yourView addSubview:spinner]; 

in yourview i give my uiviewcontroller name but its giving error i have changed to

[self.view addSubview:spinner];

pls tell me where im doing wrong and what is the right way to make it.. thanks


Solution

  • Man I got the problem...I think you are adding white activity indicator on white view that's why it is not being display but it is there for sure so...use some other style UIActivityIndicatorViewStyleGray

    -(void)temp
    {
     spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
     spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
     [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
     [self.view addSubview:spinner];
     [spinner startAnimating];
     [spinner release];
    }