我是 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”真的让我发疯了。我已经打开了 Zombie Objects,现在 Xcode 告诉我:
[AppDelegate mapView:didUpdateUserLocation:]: message sent to deallocated instance 0xde1b700
(lldb)
我已经(!)打开了新的 ARC 东西,但是我把它关掉了,仍然得到同样的错误。如您所见,我的代码中什至没有至少一个版本。