我创建了一个使用大量容器视图的应用程序。今天我发现在iOS 5中不支持嵌套segue(感谢Xcode让我知道)。 所以现在我有很多嵌套segue,它们之间传递数据。
我正在使用此代码将ViewControllers加载到UIView中,而不是从IB加载容器:
根视图控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
NewsViewController *news = [storyboard instantiateViewControllerWithIdentifier:@"NewsViewControllerID"];
news.view.frame = self.newsSection.bounds;
[self.newsSection addSubview:news.view];
[self addChildViewController:news];
[news didMoveToParentViewController:self];
// Do any additional setup after loading the view.
}
我该如何使用上述方法并仍然将数据传递给NewsViewController(类似于prepare for segue)?
我尝试在上述内容中插入以下内容:
NewsViewController *news = [storyboard instantiateViewControllerWithIdentifier:@"NewsViewControllerID"];
news.view.frame = self.newsSection.bounds;
news.myLabel.text = @"Test";
[self.newsSection addSubview:news.view];
但标签不会改变。
我更喜欢仅传递数据而不使用单例或委托。
谢谢。
addChildViewController
,但没有使用必要的didMoveToParentViewController
。根据文档:如果您正在实现自己的容器视图控制器,则在完成到新控制器的转换后或(如果没有转换)在立即调用addChildViewController:方法后,它必须调用子视图控制器的didMoveToParentViewController:方法。
- Rui Peres