我有一个提供PageViewController教程场景的应用程序。在我的设置页面中,我有一个返回到PageViewController的按钮,标记为IntroViewController。
当教程第一次出现时,它工作正常。但是当我回去时,PageViewController底部的点消失了。知道为什么会这样吗?
这是IntroViewController.m
#import "IntroViewController.h"
@interface IntroViewController ()
@end
@implementation IntroViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the data model
_pageTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Another one!"];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
_pageImages = @[@"IntroExpand.png", @"IntroSlow.png", @"IntroImport.png", @"IntroRename.png"];
}
else {
_pageImages = @[@"IntroExpand.png", @"IntroSlow.png", @"IntroImport.png", @"IntroRename.png"];
}
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
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(0, 0, self.view.frame.size.width, self.view.frame.size.height - 5);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
[self.view bringSubviewToFront:self.ready];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)ready:(id)sender { //this is the action that the user does to dismiss the tutorial and go to the first scene
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController =
[storyBoard instantiateViewControllerWithIdentifier:@"NavigationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
#pragma mark - Page View Controller Data Source
- (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 = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"];
pageContentViewController.imageFiles = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
@end
这是IntroViewController.h
#import <UIKit/UIKit.h>
#import "PageContentViewController.h"
@interface IntroViewController : UIViewController <UIPageViewControllerDataSource>
- (IBAction)ready:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *ready;
@property (weak, nonatomic) UIPageViewController *pageViewController;
@property (strong, nonatomic) NSArray *pageTitles;
@property (strong, nonatomic) NSArray *pageImages;
@end
这是将用户从设置页面带到教程的按钮/操作。我尝试了不同的segues,modal,push等,当用户返回教程时,他们都有同样的问题,即不显示点
- (IBAction)tutorialReplay:(id)sender {
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController =
[storyBoard instantiateViewControllerWithIdentifier:@"IntroViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
如果我需要添加更多代码来帮助我,请告诉我。谢谢大家。