objective-c – 加载新视图或不同控制器的UIPageControl
发布时间:2020-12-14 17:20:57 所属栏目:百科 来源:网络整理
导读:我刚刚“尝试”了解PageControl的苹果教程.现在我应该指出,我并没有完全理解这一点,它似乎很复杂,所以如果这个问题非常明显,我道歉. 我注意到苹果从.plist加载了它的内容.如果你拥有的只有一个UILabel和一个UIImageView,那就好了又简单但是如果我做了更复杂
我刚刚“尝试”了解PageControl的苹果教程.现在我应该指出,我并没有完全理解这一点,它似乎很复杂,所以如果这个问题非常明显,我道歉.
我注意到苹果从.plist加载了它的内容.如果你拥有的只有一个UILabel和一个UIImageView,那就好了又简单但是如果我做了更复杂的事情呢?如果我希望每个“页面”都有14个不同的变量,每个“页面”上的按钮根据您的页面做其他事情,该怎么办… 所以我的问题是这个(也许这首先做起来并不聪明): 谢谢 解决方法
就在这里.您将使用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 而已! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |