您的位置:首页 > 产品设计 > UI/UE

在UIViewController中获得Container View里的embed viewController的引用

2013-09-25 10:40 309 查看
When you want to use a controller you use the UIStoryboard method instantiateViewControllerWithIdentifier:, using the identifier that you give to the controller in IB,but this method will create a new instance of the UIViewController.

You can also use the performSegueWithIdentifier:sender: method (which also instantiated the view controller). You should check out the "Using View Controllers in Your App" section in the Apple docs. It also makes reference to the fact that child view controllers are instantiated at the same time as the container controller.

- (void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{

// -- Master View Controller
if ([segue.identifier isEqualToString:@"embedViewController1"])
{
self.frontViewController = segue.destinationViewController;
self.frontViewController.delegate = self;
NSLog(@"front segue %d",self.frontViewController.sliderButton.tag);
// ...
}
// -- Detail View Controller
else if ([segue.identifier isEqualToString:@"embedViewController2"])
{
self.backViewController = segue.destinationViewController;
// ...
NSLog(@"back segue");
}
}


  

After edit: If you embed a container view in another view controller, that embedded view's controller can be referenced from the containing controller with self.childViewControllers (which will be an array, so if there is just one, you can get it with lastObject).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: