【发布时间】:2011-03-08 16:50:56
【问题描述】:
原始问题如下。 我解决了我的问题。我为 tableview 和 mapview 设置了相同的视图控制器。而且我在 viewDidLoad 中有我所有的 mapView 初始化。这两者一起给我带来了以下问题:
1) 当标签栏控制器以模态方式呈现并且我收到内存警告时,调用了 viewDidUnload(我之前什么也没做)。当模态标签栏控制器被关闭并调用 viewDidLoad 时,它重置了我的 mapView。 2) 当标签栏控制器以模态方式呈现并且我在使用视图控制器移动到标签然后切换到该标签之前收到内存警告时,我的 viewDidLoad 在我的 mapView 的控制器中被调用,它重置了我的地图,但它没有重置表格属性,使我的 tableView 无法工作。
非常感谢 Anomie 帮助我调试了这个问题,并更好地了解了这些部分是如何相互关联的。现在一切都很好,而且我的应用程序设计得更好了。
原问题: 我有一个具有地图视图的应用程序,当我以模态方式呈现选项卡栏视图控制器时,每隔一段时间,当我取消模态视图控制器时,地图就会重置回世界视图,就像按下重置按钮一样。一些细节:
- 模拟器上永远不会发生这种情况
- 在我的设备上发生这种情况时,我注意到内存警告
- 当我的应用程序中发生内存警告时,我什么都不做,所以应该没有任何东西触及地图视图
此外,我的模态视图控制器中的表格视图有时也会显示为空白(大约在内存警告时)。当它出现空白时,通常调用来获取行数、节数和数据的方法根本不会被调用。取消模态视图控制器并重新打开它后,数据就在那里,所以数据不会被删除..
我用来创建标签栏控制器、选择器和表格的代码:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's address(es)
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonAddressProperty],
nil];
picker.displayedProperties = displayedItems;
UITabBarItem *peoplePickerTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
picker.tabBarItem = peoplePickerTabBarItem;
UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
tvc.tableView.delegate = self;
tvc.tableView.dataSource = self;
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:tvc];
UIBarButtonItem *uibbiCancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(cancelTable)];
tvc.navigationItem.rightBarButtonItem = uibbiCancel;
tvc.title = @"Recents";
UITabBarItem *nvcTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:2];
nvc.tabBarItem = nvcTabBarItem;
tbc = [[UITabBarController alloc] init];
NSArray *sections = [[NSArray alloc] initWithObjects:picker, nvc, nil];
[tbc setViewControllers:sections];
[self presentModalViewController:tbc animated:YES];
[nvcTabBarItem release];
[uibbiCancel release];
[tvc release];
[peoplePickerTabBarItem release];
[picker release];
[nvc release];
[sections release];
[tbc release];
【问题讨论】:
-
您可以在模拟器中发出内存警告(在硬件菜单中)。在设备上,您可以在调试器中执行相同操作:
call (void) [[UIApplication sharedApplication] _performMemoryWarning]。也许,这有助于调试问题。
标签: iphone memory mkmapview uitableview