2012-07-21 2 views
1

나는 objective-c에 익숙하지 않으며 Xcode를 이해하려고합니다.Objective-C : "MKMapView (delegate) didUpdateUserLocation"관련 문제

는 지금, 나는 다음과 같은 코드 정말 큰 문제가 있어요 :

AppDelegate.h

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 
#import <MapKit/MapKit.h> 

@class ViewController; 

@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate> { 

    IBOutlet UIActivityIndicatorView *activityIndicator; 
    IBOutlet UITextField *locationTitleField; 
    IBOutlet MKMapView *worldView; 
    IBOutlet CLLocationManager *locationManager; 

} 

@property (strong, nonatomic) UIWindow *window; 
@property (strong, nonatomic) UIViewController *viewController; 


@end 

AppDelegate.m

#import "AppDelegate.h" 

    #import "ViewController.h" 

    @implementation AppDelegate 

    @synthesize window = window; 
    @synthesize viewController = viewController; 


    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     locationManager = [[CLLocationManager alloc]init]; 
     [locationManager setDelegate:self]; 
     [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
     [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
     [worldView setShowsUserLocation:YES]; 


     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
     self.window.rootViewController = self.viewController; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { 
    // Yes, no code here, but here's the point, where I'm getting crashes, no matter if 
    // there is some code in here, or not 
    } 
    @end 

내가하려고 할 때 문제가된다 앱을 시작하면 모든 것이 정상입니다. 그러나 "didUpdateUserLocation"은 정말로 나를 괴롭 히고 있습니다. 나는 좀비 개체 설정 한 지금 엑스 코드는 저를 말하고있다 :

[AppDelegate mapView:didUpdateUserLocation:]: message sent to deallocated instance 0xde1b700 
(lldb) 

는 내가 가진 새로운 ARC 물건에 설정,하지만 난 여전히 같은 오류가 발생, 그것을 해제 한 (!). 보시다시피, 나는 적어도 내 코드에 하나의 릴리스가 없다.

+0

어떤 Xcode 버전을 사용하고 있습니까? – wackytacky99

+0

MKMapView에서 그 대리인은 어디에서 연결 했습니까? 나는 당신이 View Controller의 펜촉으로이 작업을 수행했고 AppDelegate의 다른 인스턴스에 연결했다고 추측합니다. –

답변

0

오류 메시지를 잘못 이해하고 있습니다. AppDelegate은 할당 해제 된 후 mapView:didUpdateUserLocation: 메시지가 전송되었거나 MKMapView에 잘못된 대리인이 설정되어 있습니다. 이 메서드에 무엇이 있는지는 중요하지 않습니다. 응용 프로그램 대리자가 유효한 개체가 아니라는 점이 중요합니다. 이 오류가 발생하고 알려주는 코드가 충분하지 않다고 나타내지 만 worldView이 제대로 설정되지 않았거나 종료시 올바르게 해체되지 않았습니다.

locationManagerIBOutlet으로 신고 된 다음 사용자가 할당/가입 했습니까? nib 파일에서이 오브젝트에 대해 수행 한 모든 설정은 대체하여 ARC가 없으면 원본이 유출됩니다.

+0

예! 네 말이 맞아, 나는 대표들에 대해 생각하고 있었는데, 나는 몇몇 대표들을 잘못 연결했다! 고마워요! –