我有故事板:
如您所见,我有MenuViewController :带有容器的 UIViewController。容器是 MenuTableViewController : UITableViewController 和MenuTableView : UITableView。
我想要做的是改变我的容器(MenuTableViewController)的大小并将另一个孩子添加到我的 mainVC 中。
我将它添加到 MenuViewController 中:
-(void)viewDidAppear:(BOOL)animated {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
MenuTableViewController* secondChildVC = [sb instantiateViewControllerWithIdentifier:@"MenuTableViewController"];
[secondChildVC.view setBackgroundColor:[UIColor redColor]];
[self addChildViewController:secondChildVC];
NSLog(@"MenuTableViewController.view info: %@",secondChildVC.view);
NSLog(@"secondChildVC views: %@",[secondChildVC.view subviews]);
MenuTableViewController *firstChildVC = [self.childViewControllers objectAtIndex:0];
[firstChildVC.view setFrame:CGRectMake(160, 0, 160, 504)];
[firstChildVC.view setBackgroundColor:[UIColor greenColor]];
NSLog(@"firstChildVC views: %@",[firstChildVC.view subviews]);
}
这是我的日志:
MenuTableViewController.view info: <MenuTableView: 0x8910e00; baseClass = UITableView; frame = (0 20; 320 548); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x761eca0>; layer = <CALayer: 0x76202b0>; contentOffset: {0, 0}>
2013-05-03 17:20:10.796 TestStories[41780:c07] secondChildVC views: (
"<UIImageView: 0x76205e0; frame = (0 541; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x7620680>>",
"<UIImageView: 0x7620740; frame = (313 517; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x76207e0>>"
)
2013-05-03 17:20:10.798 TestStories[41780:c07] firstChildVC views: (
"<UITableViewCell: 0x7143110; frame = (0 320; 160 320); autoresize = W; layer = <CALayer: 0x713cc10>>",
"<UITableViewCell: 0x7140b90; frame = (0 0; 160 320); autoresize = W; layer = <CALayer: 0x7140ce0>>",
"<UIImageView: 0x7135000; frame = (0 497; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x71351b0>>",
"<UIImageView: 0x7135270; frame = (153 517; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x7135310>>"
)
为什么我的 secondChildVC 不包含 TableViewCells?不知道。
您可以看到我使用红色和绿色作为背景(红色表示 secondChildCV)。但可能永远不会出现。这是屏幕截图: