It looks like it myMethodis being called from a background thread. As a rule, all interactions with UIKit elements (including UIActivityIndicatorView) should always be performed in the main thread. Try using GCD to move the user interface code to the main queue (main aka thread).
-(void)myMethod {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *currentTitleView = [[self navigationItem] titleView];
UIActivityIndicatorView *aiview = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[[self navigationItem] setTitleView:aiview];
[aiview startAnimating];
});
void (^block)(arg1, arg2) =
^(arg1, arg2)
{
block code;
dispatch_async(dispatch_get_main_queue(), ^{
[aiview stopAnimating];
[[self navigationItem] setTitleView:currentTitleView];
});
};
}
source
share