gpt4 book ai didi

ios - MVYMenuViewController : How to destroy a view controller which was instantiated from storyboard

转载 作者:行者123 更新时间:2023-11-29 12:55:45 26 4
gpt4 key购买 nike

我正在将 MVYMenu 与 Storyboard (XCode 5/iOS7) 结合使用。我不得不修改使用 xibs 的示例。到目前为止,它是有效的,但我认为每次用户单击侧边菜单时实例化 Controller 时我都在泄漏 View Controller :

这是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UINavigationController *navigationController;
UIViewController * mrViewController;

if (indexPath.row == 0) {

mrViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"mrViewController1"];

} else if (indexPath.row == 1){

mrViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"mrViewController2"];

} else if (indexPath.row == 2){

mrViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"mrViewController3"];

} else if (indexPath.row == 3){

mrViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"mrViewController4"];

} else {

mrViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"mrViewController1"];

}

navigationController = [[UINavigationController alloc] initWithRootViewController:mrViewController];
[[self sideMenuController] changeContentViewController:navigationController closeMenu:YES];

当我监控性能时,每次单击表格单元格以显示新场景时,内存使用量都会增加。我想我必须在上面代码的某处销毁以前存在的 View Controller ,但我不知道如何以及在哪里?我是 iOS 新手,来自 Android...

最佳答案

由于您使用的是 Storyboard,因此创建一个从 tableViewController 到详细 View Controller 的推送 segue,并从 didSelectRowAtIndexPath: 方法调用这些 segue。这是在带有 Storyboard的 View Controller 之间进行转换的正确方法。它也恰好比你正在做的要容易得多。如果您的行是静态的,您甚至可以将 segues 直接 Hook 到行,您根本不需要进行任何编程!

关于ios - MVYMenuViewController : How to destroy a view controller which was instantiated from storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21197204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com