Reputation: 1361
I have an activity indicator that needs to be activated as soon as a button is clicked and then stopped after a conditional statement...
I've looked at ways online to implement this but all i can find is setting them with webviews not simply turning them on and then off again.... below is my basic problem
-(IBAction)SavePassword:(id)sender{
\\start animating activity indicator
if(post recieved no errors){
\\stop animating activity indicator
}
\\else{
return the user error
}
if anyone can help it would be awesome :)
Upvotes: 2
Views: 10068
Reputation: 4617
place a activity indicator with help of interface builder.
then make an iboulet of that indicator.
IBoulet UIActivityIndicator *ac;
Then declare property and senthesize it
@property(nonatomic,retain) UIActivityIndicator *ac;
in implementation class synethesize it.
@synthesize ac;
then
[ac startAnimating];
and where u want to stop
[ac stopAnimating];
Upvotes: 0
Reputation:
I have had problems with hiding and showing when it was in the same method. By setting the visibility it will not instantly change it but only at the end of the method. So in your case it will show the indicator (technically not on screen) do some stuff and then hide it again. For the user it will never appear. You can try to perform the action on a background thread but not sure if it's thread safe enough. (Because typically all drawing functions like .hidden
must occur on the main thread)
[activityIndicator performSelectorInBackground:@selector(startAnimating) withObject:nil];
Upvotes: 1
Reputation: 10475
it pretty straight forward... create an outlet and connect it in the interface builder..
@property(nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
in the implementation just use these two methods to start and stop the animation...
[self.activityIndicator startAnimating];
and
[self.activityIndicator stopAnimating];
Upvotes: 10