iPhone 中的 ViewWillAppear 查询
我在 viewWillAppear 方法中设置了以下代码。
- (void)viewWillAppear:(BOOL)animated
{
//some code of ausregion
mapView.region = AusRegion;
mapView.showsUserLocation = NO;
addressField.text = [NSString stringWithFormat:@""];
[super viewWillAppear:animated];
}
当我的应用程序启动第一个屏幕时,它打开得很好。这是我的地图应用程序,我在按钮单击事件上设置了代码来执行某些操作。 [例如。文本字段填充当前地址,地图放大到带有注释的当前位置]。现在,当我跳到另一个列表视图控制器并返回到我的第一个屏幕时,- (void)viewWillAppear:(BOOL)animated 方法再次被调用,并带有空白文本字段、没有当前位置等。我想保留具有先前更改的屏幕[例如。文本字段填充当前地址,地图放大到带注释的当前位置]。从列表视图控制器返回到我的第一个屏幕后。
我应该如何实现这个目标?
编辑: 我在以下操作中调用列表视图控制器
RootViewController *list =
[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
[self presentModalViewController:list animated:YES];
从 RootViewController 返回后,我想要带有当前注释的地图视图,因为我在 RootViewController 中获取列表视图之前执行操作,而不仅仅是澳大利亚大陆。
I have set the following code in a viewWillAppear method.
- (void)viewWillAppear:(BOOL)animated
{
//some code of ausregion
mapView.region = AusRegion;
mapView.showsUserLocation = NO;
addressField.text = [NSString stringWithFormat:@""];
[super viewWillAppear:animated];
}
It opens well when my application launch first screen. This is my map application and I have set code on button click event to perform some action. [eg. textfield get filled with current address and map get zoom in to current location with annotation]. Now when I jump on another list view controller and get back to my first screen the - (void)viewWillAppear:(BOOL)animated method again get called with blank textfield, no current location etc. I want to retain the screen with previous changes [eg. textfield filled with current address and map zoom in to current location with annotation]. after returning from listview controller to my first screen.
How should I achieve this?
Edited:
I am calling list view controller on following action
RootViewController *list =
[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
[self presentModalViewController:list animated:YES];
And after returning from RootViewController I want Map View with current annotation as I performed action before getting list view in RootViewController instead of just Australia continent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 viewDidLoad 而不是 viewWillAppear。然后,该代码仅在视图加载(从笔尖)时运行,而不是每次重新出现时运行。
Try using viewDidLoad instead of viewWillAppear. Then that code will only run when the view is loaded (from the nib), and not every time it will re-appear.