Objective-C:与“MKMapView(委托)didUpdateUserLocation”
麻烦我是新来objective-c,我想了解Xcode。Objective-C:与“MKMapView(委托)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”真的让我疯狂。我已经打开僵尸对象和现在的Xcode告诉我:
[AppDelegate mapView:didUpdateUserLocation:]: message sent to deallocated instance 0xde1b700
(lldb)
我打开了新的ARC的东西,但我已经把它关闭,仍然得到同样的错误(!)。正如你所看到的,我甚至没有在我的代码中至少有一个版本。
您误解了错误信息。您的AppDelegate
正在被释放后被发送mapView:didUpdateUserLocation:
消息或MKMapView
具有无效的委托集。这个方法中的内容并不重要,重要的是应用程序委托不是一个有效的对象。你没有说当你得到这个错误,你没有显示足够的代码可以告诉,但你的worldView
没有被正确设置或退出正确拆除。
为什么你的locationManager
宣布为IBOutlet
然后由你分配/管理?在你的nib文件中你为这个对象所做的任何设置都会被替换掉,如果没有ARC,原始的会泄漏。
是的!你是对的,我正在考虑代表,我真的把一些代表连接错了!非常感谢! – 2012-07-21 17:52:34
您使用的是什么版本的Xcode? – wackytacky99 2012-07-21 16:06:20
你从哪里开始从你的MKMapView到它的代理的连接?我猜你在视图控制器的笔尖上做了这个,并且将它连接到AppDelegate的一个*不同*实例。 – 2012-07-21 16:35:38