一个简单的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简单例子的更多相关文章

  1. OC开发_Storyboard——iPad开发

    iPad开发(Universal Applications) 一.iPad 1.判断是否在iPad上 BOOL iPad = ([[UIDevice currentDevice] userInterf ...

  2. OC开发_Storyboard——Core Data

    一 .NSManagedObjectContext 1.我们要想操作Core Data,首先需要一个NSManagedObjectContext2.那我们如何获得Context呢:创建一个UIMana ...

  3. OC开发_Storyboard——block和动画

     一.协议 @optional :可选的 @requied :必须实现的  二.block 代码块 1. 以一个^开头,然后是参数,然后是一个大括号,包含我们的代码块 [aDictionary enu ...

  4. OC开发_Storyboard——视图控制生命周期以及NSNotifications

    一.生命周期 1.ViewDidLoad: 一般的初始化,除了几何图形的初始化(这个时候还没确定) 2.ViewWillAppear: 代表你的视图将要在屏幕上显示,可能会调用多次,对不可见时可能能改 ...

  5. OC开发_Storyboard——MapKit

    一.Core  Location 1.基本对象 @propertys: coordinate, altitude, horizontal/verticalAccuracy, timestamp, sp ...

  6. OC开发_Storyboard——AutoLayout

    一.autolayout 自动布局: 1. 设置所有视图框架的三种方法,可以通过代码创建也可以storyboard设置 = 规则 (1 蓝线+约束:(位置) 使用蓝线,根据蓝线拖动控件,只是告诉Xco ...

  7. OC开发_Storyboard——多线程、UIScrollView

    一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...

  8. OC开发_Storyboard——UITableView

    一.tableView 1.datasource数据源 (1 构造每一个tableVIewCell的方法:cellForRowAtIndexPath,这里的 dequeueReusableCellWi ...

  9. OC开发_Storyboard——UIApplication和网络活动指示器

    一.UIApplication 只有一个实例: UIApplication *myApplication = [UIApplication sharedApplication]; 属性如果设置为YES ...

随机推荐

  1. js学习笔记14----DOM概念及子节点类型

    1.概念 DOM:Document Object Model---文档对象模型 文档:html页面 文档对象:页面中的元素 文档对象模型:是一种定义,为了能够让程序(js)去操作页面中的元素. DOM ...

  2. 【复杂】CentOS 6.4下PXE+Kickstart无人值守安装操作系统

    一.简介 1.1 什么是PXE PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持 ...

  3. MVC上传(单文件)

    后台代码: public ActionResult upload() { //获取文件对象 var file = Request.Files[0]; string suffix/*文件格式*/ = S ...

  4. Windows下安装Scrapy

    安装python 根据你的需求下载python安装包,安装python(本文基于python27)https://www.python.org/downloads/ 在 环境变量---"Pa ...

  5. Loadrunner C 编程_1

    就目前的了解.Loadrunner的脚本语言其实和C没什么区别.他内部的好多机制都是C实现的. 不过是一种“类C” 所以我从几个方面分析 1:定义常量变量和C一样 2:在LR中,C的变量和LR的参数是 ...

  6. 提高Web性能的前端优化技巧总结

  7. tiny4412 ubuntudesktop更新源(old)

    1.报错:404  Not Found [IP: 91.189.88.151 80] 2. deb http://old-releases.ubuntu.com/ubuntu/ raring main ...

  8. 改善C#程序的建议4:C#中标准Dispose模式的实现

    http://www.cnblogs.com/luminji/archive/2011/03/29/1997812.html 需要明确一下C#程序(或者说.NET)中的资源.简单的说来,C#中的每一个 ...

  9. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto

    控制台: 2016-4-1 16:32:06 org.hibernate.annotations.common.Version <clinit> 信息: Hibernate Commons ...

  10. Python 爬虫知识点 - XPath

    http://cuiqingcai.com/2621.html 一.基础介绍 <bookstore> <book> <title>Harry Potter</ ...