My UIActivityIndicatorView always crashes my app.
When I press my download button, the indicator shows and starts spinning.
But when I stop it, I just have to touch the screen somewhere and my app crashes.
.h
@interface DownloadViewController : UIViewController < FinishedParsing, NSFetchedResultsControllerDelegate >
{
UIActivityIndicatorView* indicator;
}
@property (nonatomic, retain) UIActivityIndicatorView* indicator;
- (void)initSpinner;
- (void)spinBegin;
- (void)spinEnd;
.m
@implementation DownloadViewController
@synthesize indicator;
- (IBAction)download:(id)sender
{
[self initSpinner];
[self spinBegin];
[OJSGatewayCommunicationService parseArticles :self];
}
- (void)initSpinner
{
self.indicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
// we put our spinning "thing" right in the center of the current view
CGPoint newCenter = (CGPoint) [self.view center];
indicator.center = newCenter;
[self.view addSubview:indicator];
}
- (void)spinBegin
{
[indicator startAnimating];
}
- (void)spinEnd
{
self.indicator.hidesWhenStopped = YES;
[indicator stopAnimating];
indicator.hidden = TRUE;
[indicator removeFromSuperview];
}
- (void) fetchPDF:(NSMutableArray *)chapters
{
[self spinEnd];
...
}
Instead or autoreleasing it, take control of it and release it manually by calling self.indicated = nil after you’re done with it and release it in dealloc.
That way, you’re sure it won’t vanish without warnings…