UIViewController的误用

如果在一个UIViewController中有如下代码,你可能就在误用UIViewController


viewController.view.bounds = CGRectMake(50, 50, 100, 200);
[viewController.view addSubview:someOtherViewController.view];

官方添加subView的方式

Listing 14-1 Adding another view controller’s view to the container’s view hierarchy


-(void) displayContentController: (UIViewController*) content;
{
[self addChildViewController:content]; // 1
content.view.frame = [self frameForContentController]; // 2
[self.view addSubview:self.currentClientView];
[content didMoveToParentViewController:self]; // 3
}

Listing 14-2 Removing another view controller’s view to the container’s view hierarchy


-(void) hideContentController: (UIViewController*) content
{
[content willMoveToParentViewController:nil]; // 1
[content.view removeFromSuperview]; // 2
[content removeFromParentViewController]; // 3
}

参考连接:

UIViewController的误用
0)Abusing UIViewController

  1. view controller programming guide for ios

2)view controller basics

你可能感兴趣的:(UIViewController的误用)