原始問題如下。 我解決了我的問題。我爲tableview和mapview設置了相同的視圖控制器。我在viewDidLoad中擁有了所有的mapView init。這些都一起對我來說有以下問題:MKMapView不斷重置回世界視圖
1)當標籤欄控制器模態地呈現,我收到一個內存警告調用viewDidUnload(我什麼都沒有在之前)。當模式標籤欄控制器被解僱並且viewDidLoad被調用時,它重置我的mapView。 2)當標籤欄控制器以模態方式呈現,並且在移動到帶有視圖控制器的選項卡並切換到該選項卡之前收到內存警告時,我的viewDidLoad在我的mapView控制器中調用,它重置了我的地圖,重置表格屬性,以便我的tableView不起作用。
非常感謝Anomie幫助我調試此問題,並更好地瞭解這些碎片是如何連接的。事情現在很好,我的應用程序有更好的設計。
原題: 我有了一個MapView,當我提出一個標籤欄視圖控制器模態,每過一段時間,當我取消模態視圖控制器的地圖重置回世界觀就像一個復位的應用按鈕被按下。有幾個細節:
- 這在模擬器上從未發生過
- 我注意到身邊發生這種情況我的設備上的時間內存警告
- 我沒有做任何事情,當內存不足警告我的應用程序發生,所以沒有什麼應該已經觸及地圖視圖
另外,我的模態視圖控制器中的tableview有時也顯示爲空(以及內存警告的時間)。當它出現空白時,通常不會調用通常用於獲取行數,節數和數據的方法。在取消模態視圖控制器,並重新打開它時,數據是有細,所以數據是沒有得到清除..
代碼我用來創建標籤欄控制器,選擇器和表:
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]'。也許,這有助於調試問題。 – 2011-03-08 21:40:59