从另一个UIViewController及其事件中复制UIView

时间:2014-02-24 23:51:29

标签: ios objective-c events uiview uiviewcontroller

我的项目我正在构建5个相同页面但仅内容更改。 所以在我的 AUIViewController 中,我可以切换页面,如TabBarController ,并获取由 SegmentedControl 选择的视图。问题是我在 GUIViewController 中执行的事件和功能不是调用。它就像简单的观点。我怎么能这样做呢。

任何答案将不胜感激:)

代码并不完全相同,但是它可以正常工作。

AUIViewController.m:

-(void) viewDidLoad
{
  ...
  ...
  for (.. i <= 5 ..) {
   UIStoryboard      *sb   = [UIStoryboard storyboardWithName:@"Main" bundle:NULL]                                        
   UIViewController   *g   =  [sb instantiateViewControllerWithIdentifier:@"GController"];
   [self.content addSubView:a.view]
   [slef.viewControllers addObject:g]
  }
  UIViewController* first =  [viewControllers objectAtIndex:0];
  [self.content bringSubviewToFront:first.view];
}

AUIViewController.h:

....
@proprety (strong,nonatomic) UIView content; // it's a containair
@proprety NsMuableArray* controllerView;
....

1 个答案:

答案 0 :(得分:1)

问题是viewController没有留下来。为了保留它并允许它控制视图,你需要将它添加为childViewController。

添加:

UIViewController* first =  [viewControllers objectAtIndex:0];
[self.content bringSubviewToFront:first.view];

//新东西

[first willMoveToParentViewController:self];
[self addChildViewController:first];

那应该可以解决你的问题。