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 ...
随机推荐
- js学习笔记20----addClass,removeClass函数封装
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 各种api接口
实用号码归属地查询(IP 地址,手机号码): 默认格式: http://api.liqwei.com/location/ (使用来访者的 IP 地址) 指定 IP 地址格式: http://api.l ...
- e671. 在缓冲图像中存取像素
// Get a pixel int rgb = bufferedImage.getRGB(x, y); // Get all the pixels int w = bufferedImage.get ...
- 关于document.createDocumentFragment()(转)
documentFragment 是一个无父对象的document对象. 他支持以下DOM2方法: appendChild, cloneNode, hasAttributes, hasChildNod ...
- 初识Comet技术
一.服务器推送技术概述 服务器推送技术(Servers Push)的基础思想是将浏览器主动查询信息改为服务器主动发送信息.服务器发送一批数据,浏览器显示这些数据,同时保证与服务器的连接.当服务器需要再 ...
- C#获取并修改文件扩展名的方法
本文实例讲述了C#获取并修改文件扩展名的方法.分享给大家供大家参考.具体分析如下: 这里使用C#编程的方法改变文件扩展名的文件,必须使用Path类. Path类用来解析文件系统路径的各个部分.静态方法 ...
- Linux(Ubuntu)下搭建ASP.NET Core环境
今天来学习一下ASP.NET Core 运行在Ubuntu中.无需安装mono . 环境 Ubuntu 14.04.4 LTS 服务器版 全新安装系统. 下载地址:http://mirrors.neu ...
- Unity的Asset Store商店下载文件路径
如果之前在Asset Store商店下载过资源包,结果下次用的时候找不到了,不用急,其实Unity把它自动保到下面这个目录了,最后一个文件夹名与版本号有关,找到前面的即可. C:\Users\Admi ...
- TODO的用法
visual studio提供//TODO标记,不过不会在右边标记处明显标识,需要你选择菜单栏的视图进行查看.方法如下: 1.首先在你还未完成的地方打上TODO标记,以下方式均可: 1)//TODO: ...
- 世纪佳缘信息爬取存储到mysql,下载图片到本地,从数据库选取账号对其发送消息更新发信状态
利用这种方法,可以把所有会员信息存储下来,多线程发信息,10秒钟就可以对几百个会员完成发信了. 首先是筛选信息后爬取账号信息, #-*-coding:utf-8-*- import requests, ...