开发者

App crash with "Debugging Terminated"

开发者 https://www.devze.com 2023-01-20 18:05 出处:网络
I have CLLocation variable declared i gave it a value but when i use it at other place, app crash with \"Debugging Terminated\" without any logs in console

I have CLLocation variable declared i gave it a value but when i use it at other place, app crash with "Debugging Terminated" without any logs in console

CLLocation *userLoc;

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    userLoc=newLocation;
    [self somefunction];
}
-(void) somefunction
{
NSLog(@"%@",userLoc);
}

here it log userLoc properly

but in my other method

- (void) tableView:(UITableView *)tableView didSel开发者_JAVA百科ectRowAtIndexPath:(NSIndexPath*) indexPath
{
NSLog(@"%@",userLoc);
}

here app crash. Please help


Core Location provides you with autoreleased CLLocation object in delegates method, so it becomes invalid outside that method. To preserve it you need to retain location value:

userLoc=[newLocation retain];

Or, better, declare a property for your userLoc variable with retain attribute and use it the following way:

self.userLoc = newLocation;

P.S. Memory management guide is really a must-read...

0

精彩评论

暂无评论...
验证码 换一张
取 消