1

私はobjective-cが初めてで、Xcodeを理解しようとしています。

現在、次のコードで非常に大きな問題を抱えています。

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」は本当に私を夢中にさせています。ゾンビ オブジェクトを有効にすると、Xcode から次のように通知されます。

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

(!) 新しい ARC をオンにしましたが、オフにしても同じエラーが発生します。ご覧のとおり、私のコードには少なくとも 1 つのリリースが含まれていません。

4

1 に答える 1

0

エラー メッセージを誤解しています。割り当てが解除された後にメッセージAppDelegateが送信されているか、無効なデリゲートが設定されています。このメソッドに何が含まれているかは問題ではなく、アプリケーション デリゲートが有効なオブジェクトではないことだけが重要です。このエラーがいつ発生したかはわかりませんし、伝えるのに十分なコードも表示されませんが、終了時に正しくセットアップされていないか、正しく取り壊されています。mapView:didUpdateUserLocation:MKMapViewworldView

locationManagerとして宣言されてから、割り当て/初期化されるのはなぜIBOutletですか? nibファイルでこのオブジェクトに対して行った設定は、置き換えると失われ、ARCがないとオリジナルがリークします.

于 2012-07-21T16:35:35.140 に答える