标签栏和Mapview问题 [英] Tab bar and Mapview issues
问题描述
我真的很困惑这个问题.我最近在应用程序中的mapview选项卡遇到了问题.甚至达到重新开始的地步.我只是想知道我是唯一遇到此问题的人还是在这里做错了什么.
I'm really confused about this issue. I have recently been having issues with my mapview tab in my application. Even to the point of starting over again. I'm just wondering if I am the only one having this issue or am I doing something wrong here.
我对iOS还是很陌生,但是我知道如何定义mapview的中心和跨度以便以用户的位置为中心.
I am fairly new to iOS but I know how to define a mapview's center and span in order to center on the user's location.
我已经在它自己的视图中构建了它,并且似乎可以正常工作,但是当我将其放在选项卡控制器中时...出现了问题.在显示用户位置时,地图保持缩小状态.应该可以放大用户的位置.
I've built this in its own view and it seems to work but when I put it in a tab controller...I have an issue. The map stays zoomed out while showing the user's location. It's supposed to show the user's location zoomed in.
我的MapViewController:
My MapViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.mapView.delegate self];
[self.mapView setShowsUserLocation:YES];
// Do any additional setup after loading the view from its nib.
}
-(void)mapView:(MKMapView *)mapView
didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[self.mapView setRegion:region animated:YES];
}
我还认为这可能与我在委托中创建选项卡控制器的方式有关.
I also thought it could have something to do with the way I created the tab controller in the delegate.
我的应用程序委托人:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[NWSWelcomeViewController alloc] initWithNibName:@"NWSWelcomeViewController" bundle:nil];
UIViewController *viewController2 = [[NWSMapViewViewController alloc] initWithNibName:@"NWSMapViewViewController" bundle:nil];
// UIViewController *viewController3 = [[NWSSettingsViewController alloc] initWithNibName:@"NWSSettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, /* viewController3 */];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我正在为iOS 5.1编写程序,并且正在使用最新的Xcode.
I am writing for iOS 5.1 and I am using the latest Xcode.
是的,我在mapView上启用了缩放设置.
Yes, I have the settings for zooming enabled on the mapView.
我只想获取用户位置,以将地图视图放大到用户的位置.
I just want to get the user location to zoom in the mapview to the user's location.
推荐答案
viewDidLoad
中的这一行:
[self.mapView.delegate self];
不执行任何操作(它正在尝试将消息self
发送到self.mapView.delegate
).
does nothing (it is trying to send the message self
to self.mapView.delegate
).
它实际上并没有设置地图视图的delegate
,因此从未调用didUpdateUserLocation
.
It doesn't actually set the map view's delegate
and so the didUpdateUserLocation
never gets called.
您可能的意思是:
[self.mapView setDelegate:self];
或者这个:
self.mapView.delegate = self;
这篇关于标签栏和Mapview问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!