OC开发_Storyboard——NaviationController简单例子
一个简单的Navigation的例子,demo里面用到了上一个demo的MVC,可以参考下:http://www.cnblogs.com/daomul/p/4426063.html
建立一个Nav其实灰常简单,通过Editor->embed in ->NaviationController可以直接引入,就不具体介绍了。效果如下:

代码如下:
ShowStatesViewController.m:
//
// ShowStatesViewController.m
// testForNotification
//
// Created by bos on 15-4-15.
// Copyright (c) 2015年 axiba. All rights reserved.
// #import "ShowStatesViewController.h" @interface ShowStatesViewController () @property (weak, nonatomic) IBOutlet UILabel *charactersLabel; @end @implementation ShowStatesViewController #pragma life of the view - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. } -(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]; //when the view appear ,we should update the ui from the new value
[self UpdateUI];
} #pragma getter and setter
-(void)setTestContent:(NSAttributedString *)testContent
{
_testContent = testContent;
//if (self.view.window) {
[self UpdateUI];
//}
} #pragma private function
-(void)UpdateUI
{
//push the attributeName into
self.charactersLabel.text = [NSString stringWithFormat:@"%lu of all",(unsigned long)[[self getCharactersByAttributeName:NSForegroundColorAttributeName] length]];
} -(NSAttributedString *)getCharactersByAttributeName:(NSString *)attributedName
{
NSMutableAttributedString *character = [[NSMutableAttributedString alloc]init]; int index = ; // one by one check the range of the attribute
while(index < [self.testContent length])
{
NSRange mRange;
//the effect of range
id value = [self.testContent attribute:attributedName atIndex:index effectiveRange:&mRange]; if(value)
{
//the range of the characters
[character appendAttributedString:[self.testContent attributedSubstringFromRange:mRange]];
index = mRange.length + mRange.location;
}else{
index++;
}
} return character;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
ViewController.m
//from other segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"calulate the num"]) {
if ([segue.destinationViewController isKindOfClass:[ShowStatesViewController class]]) {
ShowStatesViewController *showVC = (ShowStatesViewController *)segue.destinationViewController;
showVC.testContent = self.content.textStorage;
}
}
}
注意的是:
1、 getCharactersByAttributeName这个方法是用来:通过属性类型(比如颜色,这里就是用的颜色)来获得具备该属性的文字,当然这个文字是属性化的文字,里面的算法中range是作为连续的字符是具备该属性的范围
2、UpdateUI主要是用来更新UI界面效果,通过获取该属性字符串的长度返回到第二个界面中显示
3、ViewController.m主要是通过这个界面传递值到 第二个界面,传递是通过segue的,需要通过判断identifier,这里需要在storyBoard中设置对应上。
demo下载:http://pan.baidu.com/s/1dDCkgt7
OC开发_Storyboard——NaviationController简单例子的更多相关文章
- OC开发_Storyboard——iPad开发
iPad开发(Universal Applications) 一.iPad 1.判断是否在iPad上 BOOL iPad = ([[UIDevice currentDevice] userInterf ...
- OC开发_Storyboard——Core Data
一 .NSManagedObjectContext 1.我们要想操作Core Data,首先需要一个NSManagedObjectContext2.那我们如何获得Context呢:创建一个UIMana ...
- OC开发_Storyboard——block和动画
一.协议 @optional :可选的 @requied :必须实现的 二.block 代码块 1. 以一个^开头,然后是参数,然后是一个大括号,包含我们的代码块 [aDictionary enu ...
- OC开发_Storyboard——视图控制生命周期以及NSNotifications
一.生命周期 1.ViewDidLoad: 一般的初始化,除了几何图形的初始化(这个时候还没确定) 2.ViewWillAppear: 代表你的视图将要在屏幕上显示,可能会调用多次,对不可见时可能能改 ...
- OC开发_Storyboard——MapKit
一.Core Location 1.基本对象 @propertys: coordinate, altitude, horizontal/verticalAccuracy, timestamp, sp ...
- OC开发_Storyboard——AutoLayout
一.autolayout 自动布局: 1. 设置所有视图框架的三种方法,可以通过代码创建也可以storyboard设置 = 规则 (1 蓝线+约束:(位置) 使用蓝线,根据蓝线拖动控件,只是告诉Xco ...
- OC开发_Storyboard——多线程、UIScrollView
一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...
- OC开发_Storyboard——UITableView
一.tableView 1.datasource数据源 (1 构造每一个tableVIewCell的方法:cellForRowAtIndexPath,这里的 dequeueReusableCellWi ...
- OC开发_Storyboard——UIApplication和网络活动指示器
一.UIApplication 只有一个实例: UIApplication *myApplication = [UIApplication sharedApplication]; 属性如果设置为YES ...
随机推荐
- Hibernate Query Language查询:
Hibernate Query Language查询: Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Language)查询提供 ...
- 编写一个Filter,除继承HttpServlet类外还需要( )。
A.继承Filter 类 B.实现Filter 接口 C.继承HttpFilter 类 D.实现HttpFilter接口 解答:B
- Nodejs入门手记 (01):Hello World的WEB程序
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Allong,谢谢! “滚滚长江东逝水,浪花淘尽英雄.是非成败转头空.” - <临江仙·杨慎·明> 很熟悉的旋律,鸡汤了一下:高考是 ...
- 【c语言】推断一个数是奇偶数
// 推断一个数是奇偶数 #include <stdio.h> void judge_sd(int a) { if ((a & 1) == 0) { printf("是偶 ...
- 基于bootstrap的Dialog
function yms_Dialog(container_id, modal_path, handle_function) { /// <summary> /// ...
- 基于SSH框架、Oracle数据库、easyui的分页显示
要求:在easyui-datagrid中完成paginaton的分页功能. 1.easyui-datagrig的配置 <table id="dg" rownumbers=tr ...
- 【Java面试题】22 JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
throws是获取异常throw是抛出异常try是将会发生异常的语句括起来,从而进行异常的处理,catch是如果有异常就会执行他里面的语句,而finally不论是否有异常都会进行执行的语句. thro ...
- 如何用MathType编辑化学等式
MathType在数学中应用非常广泛,被大量用于编辑数学公式,MathType不仅可以用来编辑数学公式,还可以编辑化学反应式,那么MathType编辑化学等式怎么操作的呢? 具体操作如下: 1.打开M ...
- Word揭秘:公式还能这么玩!
如今办公室里用Word来处理资料文档一种再普遍不过的现象了,学校的老师出试卷也离不开它.用Word编辑公式也是一个非常的技巧,玩转Word的同时,你玩转公式了吗?想要在Word中编辑公式,可不是说说就 ...
- 如何将ppt转换为高清图片?
PPT2010版本直接提供了“另存为”图片的功能,但另存为后的图片清晰度不够,这是因为office提供的默认点每英寸点数 (dpi)为96dpi,也就是说图片的尺寸为960x720像素,通过注册表可以 ...