在我的应用程序中,我想打开一个viewcontroller,里面有一张地图。在视图中加载我这样做:
- (void)viewDidLoad
{
[super viewDidLoad];
annotationPointArray = [[NSMutableArray alloc]init];
[self organizeMap];
modalMap = TRUE;
[map setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
[titleLabel setFont:[UIFont fontWithName:@"RemachineScriptPersonalUse" size:60]];
}
你可以看到我想用MKUserTrackingModeFollowWithHeading启动我的应用程序,但它不起作用,只有当我使用IBAction时它才能正常工作,这个:
- (IBAction)changeVisualMap:(id)sender{
if (!modalMap){
modalMap = !modalMap;
[map setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
[changeModalView_bt setImage:[UIImage imageNamed:@"map_bt_2.png"] forState:UIControlStateNormal];
[changeModalView_bt setImage:[UIImage imageNamed:@"map_bt_2.png"] forState:UIControlStateHighlighted];
}
else{
modalMap = !modalMap;
map.userTrackingMode = MKUserTrackingModeFollow;
[changeModalView_bt setImage:[UIImage imageNamed:@"map_bt_1.png"] forState:UIControlStateNormal];
[changeModalView_bt setImage:[UIImage imageNamed:@"map_bt_1.png"] forState:UIControlStateHighlighted];
}
}
为什么?
答案 0 :(得分:0)
viewDidLoad
可能为时尚早。请尝试在viewDidAppear
中设置跟踪模式。