UIPageViewController-浅析
@interface PageAppViewController : UIViewController<</span>UIPageViewControllerDataSource>{
}
@property (strong, nonatomic) UIPageViewController *pageController;
@property (strong, nonatomic) NSArray *pageContent;
@end
#import "PageAppViewController.h"
#import "MoreViewController.h"
@interface PageAppViewController ()
@end
@implementation PageAppViewController
@synthesize pageContent=_pageContent;
@synthesize pageController=_pageController;
- (void)dealloc{
[_pageContent release];
[_pageController release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createContentPages];// 初始化所有数据
// 设置UIPageViewController的配置项
NSDictionary *options =[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
forKey: UIPageViewControllerOptionSpineLocationKey];
// 实例化UIPageViewController对象,根据给定的属性
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options: options];
// 设置UIPageViewController对象的代理
_pageController.dataSource = self;
// 定义“这本书”的尺寸
[[_pageController view] setFrame:[[self view] bounds]];
// 让UIPageViewController对象,显示相应的页数据。
// UIPageViewController对象要显示的页数据封装成为一个NSArray。
// 因为我们定义UIPageViewController对象显示样式为显示一页(options参数指定)。
// 如果要显示2页,NSArray中,应该有2个相应页数据。
MoreViewController *initialViewController =[self viewControllerAtIndex:0];// 得到第一页
NSArray *viewControllers =[NSArray arrayWithObject:initialViewController];
[_pageController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
// 在页面上,显示UIPageViewController对象的View
[self addChildViewController:_pageController];
[[self view] addSubview:[_pageController view]];
}
// 初始化所有数据
- (void) createContentPages {
NSMutableArray *pageStrings = [[NSMutableArray alloc] init];
for (int i = 1; i < 11; i++){
NSString *contentString = [[NSString alloc] initWithFormat:@"
Chapter %d
This is the page %d of content displayed using UIPageViewController in iOS 5.
", i, i];
[pageStrings addObject:contentString];
}
self.pageContent = [[NSArray alloc] initWithArray:pageStrings];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreaviewControllerAtIndexed.
}
// 得到相应的VC对象
- (MoreViewController *)viewControllerAtIndex:(NSUInteger)index {
if (([self.pageContent count] == 0) || (index >= [self.pageContent count])) {
return nil;
}
// 创建一个新的控制器类,并且分配给相应的数据
MoreViewController *dataViewController =[[MoreViewController alloc] init];
dataViewController.dataObject =[self.pageContent objectAtIndex:index];
return dataViewController;
}
// 根据数组元素值,得到下标值
- (NSUInteger)indexOfViewController:(MoreViewController *)viewController {
return [self.pageContent indexOfObject:viewController.dataObject];
}
#pragma mark- UIPageViewControllerDataSource
// 返回上一个ViewController对象
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
// 返回的ViewController,将被添加到相应的UIPageViewController对象上。
// UIPageViewController对象会根据UIPageViewControllerDataSource协议方法,自动来维护次序。
// 不用我们去操心每个ViewController的顺序问题。
return [self viewControllerAtIndex:index];
}
// 返回下一个ViewController对象
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageContent count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
@end
MoreViewController.h
#import
@interface MoreViewController : UIViewController<</span>UIWebViewDelegate>{
}
@property (nonatomic,
retain) UIWebView *myWebView;
@property (nonatomic,
retain) id dataObject;
@end
#import
"MoreViewController.h"
@implementation
MoreViewController
@synthesize
myWebView=_myWebView;
@synthesize
dataObject=_dataObject;
-
(id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle
*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom
initialization
}
return self;
}
-
(void)dealloc{
[_myWebView release];
[super dealloc];
}
-
(void) loadView{
[super loadView];
self.myWebView =
[[UIWebView alloc]
initWithFrame:self.view.bounds];
}
-
(void)viewDidLoad{
[super
viewDidLoad];
}
-
(void)
viewWillAppear:(BOOL)paramAnimated{
[super viewWillAppear:paramAnimated];
[self.myWebView loadHTMLString:_dataObject baseURL:nil];
[self.view addSubview:self.myWebView];
}
-
(void)
viewWillDisappear:(BOOL)paramAnimated{
}
@end
-
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController;
-
(UIViewController
*)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController;
MoreViewController *initialViewController
=[self viewControllerAtIndex:0];// 得到第一页
NSArray *viewControllers
=[NSArray arrayWithObject:initialViewController];
[_pageController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
// 在页面上,显示UIPageViewController对象的View
[self addChildViewController:_pageController];
[[self view] addSubview:[_pageController view]];
[self createContentPages];//
初始化所有数据
UIPageViewController-浅析的更多相关文章
- SQL Server on Linux 理由浅析
SQL Server on Linux 理由浅析 今天的爆炸性新闻<SQL Server on Linux>基本上在各大科技媒体上刷屏了 大家看到这个新闻都觉得非常震精,而美股,今天微软开 ...
- 【深入浅出jQuery】源码浅析--整体架构
最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...
- 高性能IO模型浅析
高性能IO模型浅析 服务器端编程经常需要构造高性能的IO模型,常见的IO模型有四种: (1)同步阻塞IO(Blocking IO):即传统的IO模型. (2)同步非阻塞IO(Non-blocking ...
- netty5 HTTP协议栈浅析与实践
一.说在前面的话 前段时间,工作上需要做一个针对视频质量的统计分析系统,各端(PC端.移动端和 WEB端)将视频质量数据放在一个 HTTP 请求中上报到服务器,服务器对数据进行解析.分拣后从不同的 ...
- Jvm 内存浅析 及 GC个人学习总结
从诞生至今,20多年过去,Java至今仍是使用最为广泛的语言.这仰赖于Java提供的各种技术和特性,让开发人员能优雅的编写高效的程序.今天我们就来说说Java的一项基本但非常重要的技术内存管理 了解C ...
- 从源码浅析MVC的MvcRouteHandler、MvcHandler和MvcHttpHandler
熟悉WebForm开发的朋友一定都知道,Page类必须实现一个接口,就是IHttpHandler.HttpHandler是一个HTTP请求的真正处理中心,在HttpHandler容器中,ASP.NET ...
- 【深入浅出jQuery】源码浅析2--奇技淫巧
最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...
- 浅析匿名函数、lambda表达式、闭包(closure)区别与作用
浅析匿名函数.lambda表达式.闭包(closure)区别与作用 所有的主流编程语言都对函数式编程有支持,比如c++11.python和java中有lambda表达式.lua和JavaScript中 ...
- word-break|overflow-wrap|word-wrap——CSS英文断句浅析
---恢复内容开始--- word-break|overflow-wrap|word-wrap--CSS英文断句浅析 一 问题引入 今天在再次学习 overflow 属性的时候,查看效果时,看到如下结 ...
- 编写轻量ajax组件02-AjaxPro浅析
前言 上一篇介绍了在webform平台实现ajax的一些方式,并且实现一个基类.这一篇我们来看一个开源的组件:ajaxpro.虽然这是一个比较老的组件,不过实现思想和源码还是值得我们学习的.通过上一篇 ...
随机推荐
- MVC实用架构设计:总体设计
http://developer.51cto.com/art/201309/410166.htm
- ssh整合启动tomcat报java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils
今天搭建了一个ssh项目环境,整合后,访问项目首页,登录不进去,控制台报错,后来调试代码后,在获取数据库数据后,返回到action时,又进入了action导致死循环,其实这里是两个问题,控制台报错如下 ...
- RHEL5.8安装Sybase 15.7_x86_64
RHEL5.8安装Sybase 15.7如果您运行的是 RHEL 5 或更高版本,请使用以下设置:kernel.exec-shield = 0kernel.randomize_va_space = 0 ...
- PropertyGrid—添加属性Tab
零.引言 PropertyGrid用来显示和编辑对象的属性,前面已经简单介绍了如何使用该控件和提供不同的属性编辑方法.前面主要讲如何使用该控件,但有时,该控件无法满足我们的需求,就需要对其进行扩展.本 ...
- swfobject.js 2.2简单使用方法
swfobject.js 2.2简单使用方法 官方网址介绍http://code.google.com/p/swfobject/wiki/documentation 用法:html部分<div ...
- C#中对输出格式的初始化
一.在输出的时候,\t和8个空格是不一样的,\t是跳转到下一个水平制表符,如果你在第一个水平制表符中写有数据123,那么跳转后跳转到9的位置上,中间只有5个空格,但是如果用8个空格来做分割的话,就会有 ...
- Foundation--NSDictionary+NSMutableDictionary
键值对 key(一般为字符串对象)---vaule(必须是对象) Person *p1 =[[Person alloc ]init]; Person *p2 =[[Person alloc ]init ...
- D - Specialized Four-Digit Numbers
Description Find and list all four-digit numbers in decimal notation that have the property that the ...
- TableLayout属性
整理于http://naotu.baidu.com/file/e5880b84b1a906838116f7a45f58de78
- 从汇编看c++中的虚拟继承及内存布局(二)
下面是c++源码: class Top {//虚基类 public: int i; Top(int ii) { i = ii; } virtual int getTop() { cout <&l ...