我在解除 UIViewController 对象集合时遇到了一些麻烦。我不知道一次关闭所有加载的模式 UIViewController 对象的优雅方法。
我使用 Xcode 4 中的“故事板”,但我不使用 Segues 来映射屏幕。我使用动态代码,如下所示:
这一切都始于 MainViewController.m。我加载 [myMenuController] (菜单列表)。当用户从菜单中选择一个选项时,它会加载 [myTicketController]。在那里进行一些用户交互后,它会加载 [myNextController] 并且您会看到该模式。我动态加载了几个 UIViewControllers(这里没有 segues):
//from MainViewController.m - Load the main menu
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
myMenuController = (MyMenuController *)[storyboard instantiateViewControllerWithIdentifier:@"MyMenuController"];
myMenuController.settingsModel = settingsModel;
myMenuController.ticketStatusHandler = data;
myMenuController.rootDataModel = dataModel;
[myMenuController setModalPresentationStyle:UIModalPresentationFullScreen];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController:myMenuController animated:YES];
///////////////////////////////////////////////////////////////////////////
//from MyMenuController.m - Load the add ticket menu
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
myTicketController = (MyTicketController *)[storyboard instantiateViewControllerWithIdentifier:@"MyTicketController"];
myTicketController.settingsModel = settingsModel;
myTicketController.ticketStatusHandler = data;
myTicketController.rootDataModel = dataModel;
[myTicketController setModalPresentationStyle:UIModalPresentationFullScreen];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController:myTicketController animated:YES];
///////////////////////////////////////////////////////////////////////////////
//from MyTicketController.m - Load the next screen
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
myNextController = (MyNextController *)[storyboard instantiateViewControllerWithIdentifier:@"MyNextController"];
myNextController.settingsModel = settingsModel;
myNextController.rootDataModel = dataModel;
[myNextController setModalPresentationStyle:UIModalPresentationFullScreen];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController: myNextController animated:YES];
所以我到了应用程序的末尾并加载了更多的 UIViewControllers。假设我在加载 [myNextController] 之后再加载 4 或 5 个 UIViewController。
有没有一种通用的方法来卸载内存中的所有 UIViewControllers,然后简单地重新加载 [myMenuController]?