我刚刚学习了 IOS 编程并正在编写我的第一个 iPhone 应用程序。
我的应用程序提供有关 MKMapView 的信息,其视图控制器是 UINavigationController 的根视图控制器。如果移动信号不好,我使用 mapViewDidFailLoadingMap:withError: 使应用程序根据用户的操作将两个不同的视图控制器之一推送到导航控制器堆栈上。代码如下:
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error
{
NSLog(@"mapViewDidFailLoadingMap: %@", [error localizedDescription]);
[aiView stopAnimating];
if (mapTypeInt == 0) {
NSString *message =
[NSString stringWithFormat:@"Your signal is not currently
strong enough to download a map. Switching to table view."];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Maps Unavailable"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
if (currentMode == @"retracingSteps")
{
RetraceViewController *rvc =
[[RetraceViewController alloc] initWithNibName:@"RetraceViewController" bundle:nil];
[[self navigationController] pushViewController:rvc animated:YES];
}
else{
TripTableViewController *ttvc = [[TripTableViewController alloc] init];
[[self navigationController] pushViewController:ttvc animated:YES];
}
}
else{
[self setMapType:0];
NSString *message = [NSString stringWithFormat:
@"Your signal is not currently strong enough to download a satellite map.
Switching to Standard Map view."];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Can't Use Satellite Maps"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
}
}
昨天我在一个乡村山谷测试了较差的移动信号,并且正确的第二个视图控制器被推送到堆栈上。然后,当我锁定手机并在几分钟后重新检查应用程序时,我注意到的是,在醒来时,根视图控制器很快就会显示出来,然后是我预期的视图控制器。实际上,这样做是将第二个视图控制器的相同副本推送到堆栈上。当我不得不点击后退按钮六次才能返回根视图控制器时,我发现了这一点。
我希望应用程序在唤醒时执行的是立即显示手机锁定时处于活动状态的视图控制器,而不是根视图控制器。我不知道该怎么做。