我想補充UIPageController
到UIView
viewController
的無法添加pageViewController到的UIView
這裏是我的代碼,但它不工作,
MyViewController含有一種觀點認爲這是_viewExpense
有我想 加我viewcontroller
。
MyViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
PageViewControllerDashboard *pageViewController = [[UIStoryboard storyboardWithName:@"MoneyBag" bundle:nil] instantiateViewControllerWithIdentifier:@"PageViewControllerDashboard"];
[self addChildViewController:pageViewController];
[_viewExpense addSubview:pageViewController.view];
[pageViewController didMoveToParentViewController:self];
}
PageViewControllerDashboard
- (void)viewDidLoad {
[super viewDidLoad];
_pageTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Free Regular Update"];
// Create page view controller
self.pageViewController.dataSource = self;
pageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(10, 10, self.view.frame.size.width, self.view.frame.size.height - 100);
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
}
頁面視圖控制器數據源
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = ((pageContentViewController*) viewController).pageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((pageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageTitles count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (pageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
pageContentViewController *pageContentViewController = [[UIStoryboard storyboardWithName:@"MoneyBag" bundle:nil] instantiateViewControllerWithIdentifier:@"pageContentViewController"];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
我在哪裏犯錯,請幫忙。先謝謝你。