【发布时间】:2011-08-03 23:08:45
【问题描述】:
我正在尝试让 MKMapView 显示我当前的位置。我设法让它在具有单个视图的应用程序中工作,但现在我试图在 UITabBarController 中实现相同的视图。我的代码或多或少是一样的,但我仍然无法让它工作。
我正在关注关于 iPhone 开发的 BigNerdRanch 指南。我像他们对书中的其他视图一样实现了这个视图;我先写了init方法:
#import "CurrentLocationViewController.h"
#import "MapPoint.h"
@implementation CurrentLocationViewController
- (id)init
{
self = [super initWithNibName:@"CurrentLocationViewController"
bundle:nil];
if (self) {
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@"Location"];
UIImage *i = [UIImage imageNamed:@"Hypno.png"];
[tbi setImage:i];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[worldView setShowsUserLocation:YES];
}
return self;
}
我也通过这样做使该 init 方法成为指定的初始化器:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return [self init];
}
如您所见,我确实在我的worldview 上调用了setShowsUserLocation:YES,在我的头文件中声明为:IBOutlet MKMapView *worldView;。
我可能在这里遗漏了一些东西,但我认为该消息是使 basic 地图视图正常工作所需的唯一内容?有任何想法吗?
如有必要,我可以提供更多代码。顺便说一句,视图确实正确加载,我首先检查了一种令人讨厌的颜色,它确实显示了地图。它只是没有在上面放一个蓝色别针。
谢谢。
【问题讨论】: