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 ...
随机推荐
- kettle优化
http://blog.csdn.net/cissyring/archive/2008/05/29/2494130.aspx 1. Join 我得到A 数据流(不管是基于文件或数据库),A包含fiel ...
- jquery easyui datagrid 分页实现
通常情况下页面数据的分页显示分成真假两种.真分页是依靠后台查询时控制调出数据的数量来实现分页,也就是说页面在后台对数据进行处理,仅传输当前需要页的数据到前台来显示.而假分页则是后台一次性将所有的数据一 ...
- 用R作Polar图等
用R作如下的各国Gini系数的Polar barChart: 作上图的R代码为: library(ggplot2) GiniData<- read.csv('IncomeInequality.c ...
- jQuery Masonry-让你的网页更自然的强大的动态不规则布局插件!
Masonry是 一款非常强大的jQuery动态网格布局插件,可以帮助开发人员快速开发类似剪贴画的界面效果.和CSS中float的效果不太一样的地方在 于,float先水平排列,然后再垂直排列,使用M ...
- e660. 用一组像素创建图像
This example demonstrates how to convert a byte array of pixel values that are indices to a color ta ...
- 防止 apk反编译 jocky-- java混淆代码 (转至:http://my.oschina.net/f839903061/blog/72554)
1.下载jocky,解压后把整个文件夹复制到Eclipse的plugin目录.2.重启Eclipse,在项目上点右键,如果出现jocky菜单,则安装成功. 3.在项目上点右键,选菜单jocky-> ...
- 图片后门捆绑利用工具 – FakeImageExploiter
在这里,要向大家推荐一款名为“Fake Image Exploiter”的安全工具,该工具可以在图片文件中捆绑隐藏的恶意.bat或.exe程序,方便钓鱼或社工攻击测试过程中的入侵控制.如果受害者点击该 ...
- tomcat+nginx反向代理(实现一个服务器,一个ip共用80端口)
http://blog.csdn.net/sinat_33388558/article/details/54837051 http://www.cnblogs.com/zhouqinxiong/p/5 ...
- C++ 对象间的赋值与拷贝构造函数
1.对象间的赋值 /***A.h文件***/ #pragma once class A { public: int va; A(void); A(char* name); A(const A& ...
- oracle函数学习_根据用户id获取用户角色
create or replace function FN_GET_ROLES(v_user_id varchar2) return varchar2 istype zy_emp_cursor is ...