简体   繁体   中英

Converted to ARC App crashes on any method iPhone

I converted my app to ARC and removed all the pre-build release errors. It launches, but will crash (EXC_BAD_ACCESS) as soon as I call any method (all of which are attached to UIButtons). I also noticed that it will ask if the user will allow for the app to use the user's location, but the alert will disappear before the user can answer yes or no.

I feel like there's some very basic setting I'm missing causing this.

Here's the first method called, it won't let the user actually say if they'll allow location services. The alert fires then disappears. Does this help anyone's diagnosis?

-(void)startLocation
    {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
    }

Also, here's my didFinishLaunchingWithOptions method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    UINavigationController *nav = [[UINavigationController alloc] init];
    StartPageViewController *start = [[StartPageViewController alloc]init];
    NSManagedObjectContext *context = [self managedObjectContext];

    if (!context) 
    {
        // Handle the error.
    }

    start.managedObjectContext = context;
    nav.viewControllers = [NSArray arrayWithObjects:start, nil];

    [_window addSubview:[nav view]];
    [self.window makeKeyAndVisible];
    return YES;

}

Try retaining your navigation controller by making it a strong property on your delegate.

At the moment, I don't see any code that would cause ARC not to release nav at the end of the method. That would release start , which would release context .

All I needed to change (so far) was:

 self.window.rootViewController = nav;

instead of:

[_window addSubview:[nav view]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM