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.虽然这是一个比较老的组件,不过实现思想和源码还是值得我们学习的.通过上一篇 ...
随机推荐
- linux多线程socket编程一些心得
http://hi.baidu.com/netpet/blog/item/2cc79216d9012b54f2de32b9.html 前段时间将新的web模型办到linux上来,用epoll代替了IO ...
- MVC实用架构设计:总体设计
http://developer.51cto.com/art/201309/410166.htm
- Multiscale Combinatorial Grouping 学习和理解源代码(一)
目标探测由于所做的最新研究.因此,这一领域的一般阅读文章.发现这篇文章,效果是比较新的比较好.在如此仔细研究.贴纸和共享.下面已经发布若干个连续的,分别对论文和代码进行大致地介绍,最后依据自己的实验对 ...
- 分类: LINUX apache 访问设置配置
分类: LINUX 在一次面试的时候被问到apache访问控制的问题.由于以前对apache的访问控制都是通过iptalbes来实现的,没有实际在apache上操作过访问控制.所以只知道个大概: 在主 ...
- unix系统非roo账号安装JDK
AIX系统用户rusky(非root用户,没有权限修改/etc/profile和/etc/environment文件 )直接解压JDK.zip文件,解压后把JAVA目录拷贝到/home/rusky目录 ...
- NPOI兼容 excel2003,2007版本
根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. public int Import(string path) { IList<Studen ...
- JS实现给页面表单设置触发默认按钮
var defaultBtnId; function setDefaultButton(id) { defaultBtnId = id; } document.onkeydown = function ...
- android——字体颜色跟随状态改变
TextView的字体颜色也可以和ImageView的background一样,跟随状态发生改变.只需要自定义一下字体颜色.在color文件夹下面,新建一个颜色文件的xml. OK ,这就完成 了. ...
- C# HTML转换为WORD
使用aspose.words仅需要4句代码,即可搞定. Document doc = new Document(); DocumentBuilder builder = new DocumentBui ...
- 手把手教你使用Git(转)
Git使用教程 2014-10-25 14:29 by 云溪0707, 10532 阅读, ... 评论, 收藏, 编辑 Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系 ...