UIPageControl 加载新视图或不同控制器
我刚刚“尝试”浏览苹果的 PageControl 教程。现在我应该指出,我并没有完全理解这一点,它看起来很复杂,所以如果这个问题非常明显,我深表歉意。
我注意到苹果从 .plist 加载了其内容。现在,如果您只有一个 UILabel 和一个 UIImageView ,那么一切都很好很容易,但如果我想做一些更复杂的事情怎么办?如果我希望每个“页面”都有 14 个不同的变量,每个“页面”上有一个按钮,根据您所在的页面执行其他操作...
所以我的问题是这样的(也许这样做并不明智)首先): 有没有办法对其进行编码,以便当用户切换页面时,它会加载一个不同的控制器,该控制器恰好有自己的 .Xib 文件和已在界面生成器中创建的视图?
谢谢
I have just "attempted" to go over apples tutorial of PageControl. Now I should point out that I did not fully understand this, it seemed complex so I apologize if this question is very obvious.
I noticed that apple loaded its content from a .plist. Now thats all nice and easy if all you have is one UILabel and an UIImageView but what if I wana do something more complex? What if I want to each "page" to have like 14 different variables, a button on each "page" that does something else depending on what page you are...
So my question is this (perhaps this would not be smart to do in the first place):
Is there someway to code it so when the page is switched by the user, it loads a different controller that happens to have its own .Xib file and view already created in interface builder?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有。您将使用
UIPageViewController
。UIPageViewController
具有数据源和委托方法,这些方法根据用户向左还是向右滑动而调用。它基本上是说“嘿,给我一个 UIViewController,我应该在这个 UIViewController 之前或之后显示它。”这是一个示例:
MyPageViewController.h:
MyPageViewController.m:
就是这样!
Yes there is. You would use a
UIPageViewController
. TheUIPageViewController
has data source and delegate methods that get called depending on whether the user swipes to the left or to the right. It basically says "Hey, give me the UIViewController that I should display before or after this UIViewController."Here's a sample:
MyPageViewController.h:
MyPageViewController.m:
That's it!