I’m trying to display a view after user accepts location sharing. Here is the code:
-(void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusDenied) {
NSLog(@"Denied");
}
else if (status == kCLAuthorizationStatusAuthorized) {
NSLog(@"Accepted!");
AlertViewController *aViewController = [[AlertViewController alloc] initWithNibName:@"AlertViewController" bundle:nil];
aViewController.view.frame = CGRectMake(0, 0, 320, 460);
aViewController.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:[aViewController view]];
}
}
But I get *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xee6fc90' error at line aViewController.view.frame = ...
I put breakpoints and verified that aViewController is not 0x00000 after the alloc statement. I can’t seem to figure out what the problem is. Please suggest solutions.
I suspect an issue in the xib file or in the AlertViewController’s view initialization routine (i.e. viewDidLoad or loadView). The only way I can reason that the line setting the frame is crashing is that it’s the first time you are accessing the view property, and views are lazily loaded.
I suspect that if you replaced
with
then you would see the crash on the first line, not the second.
To debug further, I would use breaks in AlertViewController’s viewDidLoad or similar. And double-check everything in the xib.