我需要向视图添加更多视图以处理多个网址和标签上的点击。我尝试在 for 语句中做到这一点。我的代码是这样的:
// we have a UITabbarViewController for holding amongs other the parentViewController
UITabBarController *tabbedViewController = [[UITabBarController alloc] init];
// create the parentViewController
ParentViewController *parentViewController = [[ParentViewController alloc] initWithNibName:@"parentViewController" bundle:nil];
[parentViewController.view setNeedsDisplay];
// add parentViewController into tabbedViewController
tabbedPlayerViewController.viewControllers = [NSArray arrayWithObjects: ... parentViewController, nil];
// All the things are inside a UINavigationController
// push the view
[self.navigationController pushViewController:tabbedViewController animated:YES];
// setting up the views individually...
// not listed here
for (NSDictionary *url in urls) {
// init my controller with a nib file
UIViewController *webadressViewController = [[WebadressViewController alloc] initWithNibName:@"WebadressViewController" bundle:nil];
// position the view ...
// ... not listed here
// add webaddress to parent view
[parentViewController.view addSubview: webaddressViewController.view];
}
[parentViewController release];
[tabbedViewController release];
我想我可能有一些内存管理问题,因为 webaddressViewController 有 1 作为保留计数,所以它需要在我的代码中的某个地方释放。但是,如果我在 for 块中释放它,所有子视图都会消失。
我的问题是如何释放这些对象?
(正如我看到的问题如下:当我在 parentViewController 上调用 addSubview 时,它将拥有 webaddressViewController.view 但不拥有 webaddressController 本身。因此,如果我释放 webaddressViewController 它的视图也会消失。)