我试图学习UIPageViewController
s 并遇到了一个我无法解决的问题。这就是我试图做的:
- 脚步:
- 我只是在 StoryBoard 中创建了 2 个视图控制器和一个页面视图控制器。
- 然后我向 File's Owner 添加了一些代码,
PageViewController
使其表现得像 adataSource
和delegate
自身。 - 当我跑步时,一切都很顺利。
- 我在第二个视图控制器中添加了一些按钮和文本字段。
- 我跑了,效果很好。
- 现在我向第二个视图控制器添加了一个文本视图并运行。当我试图在文本视图中写一些东西时,页面控件抖动并移动到第一个视图控制器。
有没有人经历过这种情况?
@interface AMPageViewController : UIPageViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
@end
实施:
#import "AMPageViewController.h"
@interface AMPageViewController ()
{
UIViewController *mainController;
UIViewController* socController;
}
@end
@implementation AMPageViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
mainController = (UIViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"First"];
socController = (UIViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"Second"];
[self setViewControllers:@[mainController]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
self.dataSource = self;
self.delegate = self;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if (viewController == socController )
return mainController;
else return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
if (viewController == mainController )
return socController;
else return nil;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return 2;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
@end