Can anyone tell me why this comparison keeps making my app freeze and crash?
NSArray *viewControllerArray = [controlFromMap.navigationController viewControllers];
NSUInteger parentViewControllerIndex = [viewControllerArray count] - 3 // o开发者_如何学运维r - whatever;
NSLog(@"Parent view controller: %@", [viewControllerArray objectAtIndex:parentViewControllerIndex]);
if([[[viewControllerArray objectAtIndex:parentViewControllerIndex]stringValue] isEqualToString: @"FromAddressController"]){
_mapView.showsUserLocation = NO;
}
else{
_mapView.showsUserLocation = YES;
}
[viewControllerArray objectAtIndex:parentViewControllerIndex] should return an instance of UIViewController subclass. Make sure it responds to -stringValue or (assuming FromAddressController is a class name) make it so:
if([[viewControllerArray objectAtIndex:parentViewControllerIndex] class] == [FromAddressController class])
If you add:
NSLog(@"parentViewControllerIndex: %d", parentViewControllerIndex);
after the line:
NSUInteger parentViewControllerIndex = [viewControllerArray count] - 3;
What value do you see in the console?
Also, this line:
if([[[viewControllerArray objectAtIndex:parentViewControllerIndex]stringValue] isEqualToString: @"FromAddressController"]){
looks suspicious to me.
I checked the documentation and the UIViewController
class does not appear to have a -stringValue
method. So you probably will get an unrecognized selector exception and your application will crash.
Perhaps you mean nibName
instead of stringValue
?
精彩评论