【发布时间】:2011-01-20 18:55:04
【问题描述】:
我的应用有一个标签栏控制器,其中一个标签项是拆分视图控制器。它的主视图控制器(即在索引 0 处)是一个从 nib 加载的导航控制器,因为它是自定义导航栏。
如果这听起来有点晦涩难懂,那是因为 1) 无法将 SVC 添加到 IB 中的 TBC 和 2) iOS 4.2 splitview-navbar-colorTint 错误。事实上,直到昨天实施解决方法后,我才遇到内存不足警告的问题。
在解决方法之前,我使用 2 个导航控制器启动 SVC,并将其添加到 TBC 中(由于 IB 对标签栏的限制)并且没有问题 - 好吧,除了那个苹果错误。
小workaround demo 也可以正常工作,即使在内存不足警告之后。但它不涉及标签栏的额外开销。
但在my adaption of the workaround demo 中,它开始变成梨形。在显示拆分视图时发送内存不足警告,整个左侧(主视图)消失。设备上的行为相同,事实上我是在那里第一次发现的。
我对发生了什么感到困惑。显示的视图(导航 cont 的根视图)由表视图子类控制。我已经覆盖了 didReceiveMemoryWarning 但这没有帮助。此外(相应地!),超级视图不是零。这是一个 UITableView。完全正确。
所以,我在想导航控制器正在被释放?但是哪里?为什么不在原始演示中?现在的不同是添加了我的标签栏控制器。这是我将其添加到标签栏的代码:
- (void) addTabItemSplitViewWithNavConRoot:(BOOL)hasRootNC {
// init master/detail views
SV1RootViewController *rvc = [[SV1RootViewController alloc] initWithNibName:@"SVC1RootView" bundle:nil];
SV1DetailViewController *dvc = [[SV1DetailViewController alloc] initWithNibName:@"SVC1DetailView" bundle:nil];
rvc.detailViewController = dvc;
UINavigationController *nc = nil;
if (hasRootNC) {
nc = [self.pSVC1.viewControllers objectAtIndex:0];
nc.viewControllers = [NSArray arrayWithObjects:rvc, nil];
nc.navigationBar.tintColor = [UIColor redColor];
} else {
nc = nil;
}
UIViewController *vc = (hasRootNC)? (UIViewController*)nc :rvc;
UISplitViewController *svc = [self newSplitViewControllerWithMasterVC:vc detailVC:dvc];
svc.delegate = dvc;
// init the tab bar item
svc.tabBarItem = [[UITabBarItem alloc] initWithTitle:(hasRootNC)? @"SplitView with Nav Root":@"Simple SplitView"
image:nil
tag:0];
// int the split view
NSMutableArray *controllersArray = [NSMutableArray arrayWithArray:self.pTabBarController.viewControllers];
[controllersArray addObject:svc];
[self.pTabBarController setViewControllers:controllersArray];
// cleanup
[nc release];
[rvc release];
[dvc release];
[svc release];
}
- (UISplitViewController*) newSplitViewControllerWithMasterVC:(UIViewController*)masterView
detailVC:(UIViewController*)detailView {
UISplitViewController *svc = [[UISplitViewController alloc] init];
NSMutableArray *controllersArray = [NSMutableArray arrayWithObjects:masterView, detailView, nil];
[svc setViewControllers:controllersArray];
return svc;
}
请问有人对我有什么想法吗? :)
快把我逼疯了!!!
【问题讨论】:
-
请尝试重新格式化您的代码。
标签: memory memory-management ios4 uitabbarcontroller uisplitviewcontroller