我刚刚“尝试”了解PageControl的苹果教程.现在我应该指出,我并没有完全理解这一点,它似乎很复杂,所以如果这个问题非常明显,我道歉.
我注意到苹果从.plist加载了它的内容.如果你拥有的只有一个UILabel和一个UIImageView,那就好了又简单但是如果我做了更复杂的事情呢?如果我希望每个“页面”都有14个不同的变量,每个“页面”上的按钮根据您的页面做其他事情,该怎么办…
所以我的问题是这个(也许这首先做起来并不聪明):
是否有某种程度的代码编写它,所以当用户切换页面时,它会加载一个不同的控制器,恰好有自己的.Xib文件和视图已在界面构建器中创建?
谢谢
解决方法
就在这里.您将使用UIPageViewController. UIPageViewController具有数据源和委托方法,可根据用户是向左还是向右滑动来调用.它基本上说“嘿,给我UIViewController我应该在这个UIViewController之前或之后显示.”
这是一个示例:
MyPageViewController.h:
@interface MyPageViewController : UIPageViewController <UIPageViewControllerDataSource,UIPageViewControllerDelegate> @end
MyPageViewController.m:
#import "MyPageViewController.h" @implementation MyPageViewController - (id)init { self = [self initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; if (self) { self.dataSource = self; self.delegate = self; self.title = @"Some title"; // set the initial view controller [self setViewControllers:@[[[SomeViewController alloc] init]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL]; } return self; } #pragma mark - UIPageViewController DataSource methods - (UIViewController *)pageViewController:(UIPageViewController *)pvc viewControllerBeforeViewController:(UIViewController *)vc { // here you put some logic to determine which view controller to return. // You either init the view controller here or return one that you are holding on to // in a variable or array or something. // When you are "at the end",return nil return nil; } - (UIViewController *)pageViewController:(UIPageViewController *)pvc viewControllerAfterViewController:(UIViewController *)vc { // here you put some logic to determine which view controller to return. // You either init the view controller here or return one that you are holding on to // in a variable or array or something. // When you are "at the end",return nil return nil; } @end
而已!