今天我会问你是否有一种方法可以调用另一个视图控制器的方法而不是初始化它,或者只是如何将该视图控制器作为在 .h 文件中声明的全局变量。请帮帮我。我正在使用 PageViewController,我必须使用已经初始化的 contentViewController 的方法。
在这里我创建了我的 ViewControllers:
- (void)createTheContent {
NSLog(@"createTheContent");
pageController = nil;
//[pageController removeFromParentViewController];
//[pageController awakeFromNib];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options: options];
pageController.dataSource = self;
[[pageController view] setFrame:CGRectMake(0, 0, 320, 365)];
initialViewController = [self viewControllerAtIndex:0];
NSMutableArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:pageController];
[[self view] addSubview:[pageController view]];
[pageController didMoveToParentViewController:self];
}
这是我在 .h 文件中的属性:
contentViewController *initialViewController;
}
//Page View Controller Properties
@property (strong, nonatomic) UIPageViewController *pageController;
@property (strong, nonatomic) NSArray *pageContent;
@property (strong, nonatomic) NSMutableArray *pageStrings;
@property (strong, nonatomic) id dataObject;