在UIViewControllers之间委派

时间:2014-06-17 12:20:48

标签: ios objective-c uiviewcontroller delegates

我有以下ViewControllers结构:

enter image description here

PageViewController包含PhotoViewController和VideoViewController,它以编程方式更改,因此没有任何segues。

我希望允许VideoControlViewController使用CameraViewController中的方法。我尝试使用以下代码:

self.videoControlViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"videoControlViewController"];
self.videoControlViewController.delegate = self;

它不起作用,因为方法" instantiateViewControllerWithIdentifier"创建VideoViewController的新实例。这是我发现的同样问题的主题:

http://iphonedevsdk.com/forum/iphone-sdk-development/109543-string-becomes-nil-after-viewdidload-with-protocol-and-delegate.html

如果没有任何segue或过渡,如何将self.VideoControlViewController指向故事板中的实例?


enter image description here

- (void)viewDidLoad {

    [super viewDidLoad];
    self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    self.viewControllers = @[@"photoControlViewController", @"videoControlViewController"];
    self.pageViewController.dataSource = self;
    [[self.pageViewController view] setFrame:[[self view] bounds]];
    [self.pageViewController setViewControllers:[NSArray arrayWithObject:[self viewControllerAtIndex:[self.viewControllers indexOfObject:@"photoControlViewController"]]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
    [self addChildViewController:self.pageViewController];
    [[self view] addSubview:[self.pageViewController view]];
    [self.pageViewController didMoveToParentViewController:self];

}

0 个答案:

没有答案