I placed a UIActivityIndicatorView in my nav bar by doing the following.
in the .h file
@property (strong, nonatomic) UIActivityIndicatorView *mySpinner;
in the .m file
- (void)viewDidLoad
{
[super viewDidLoad];
_mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_mySpinner.translatesAutoresizingMaskIntoConstraints = NO;
_mySpinner.hidesWhenStopped = YES;
UIBarButtonItem *spinnerButton = [[UIBarButtonItem alloc] initWithCustomView:_mySpinner];
self.navigationItem.rightBarButtonItem = spinnerButton;
[_mySpinner startAnimating];
//some other stuff
}
This worked great for both iOS 7 and iOS 8, the only two systems I am targeting. The App went to Apple for review, passed and is now on the App Store. So I download it onto one of my phones (running iOS 8) from the store at it works, download it to another phone running iOS 7 and it crashes when I go to the screen with the UIActivityIndicatorView. I boot back up Xcode and run the App in release mode and was able to make it crash again. This is the message.
Assertion failure in -[UINavigationBar layoutSublayersOfLayer:]
and this
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UINavigationBar's implementation of -layoutSubviews needs to call super.'
I have tried to call layoutSublayersOfLayer, but that did not work. I also tried to use Auto Layout on the UIActivityIndicatorView, but that told me that I can't put constraints on this yet, because the view is not ready.
However, if I make a fresh project and run it, the UIActivityIndicatorView works, just like it did before I submitted my App. I even ran the test in release mode as well. I have deleted derived data, clean, build, restart, reboot. But now, in iOS 7 the app will always crash if I add the UIActivityIndicatorView. Does anyone have any insight as to what is happening? I have pretty much deleted everything from the viewDidLoad method to see if it was something else causing it, to no avail. Any help would be appreciated. Right now I am using an if then statement to check if the iOS is 7 or 8, if 8 I add the Indicator, but I really don't want to do that. Thanks!!
I see my question is very similar to THIS one, but that does not have any answers or comments.