//
// AppDelegate.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *rootViewController = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = nav; return YES;
}
//
// ViewController.h
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import "SubViewController.h" @interface ViewController : UIViewController <sendTitleReport> @end //
// ViewController.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SubViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor cyanColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
[btn setTitle:@"push" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; self.navigationItem.title = @"按钮一"; } - (void)btnClicked
{
NSLog(@"-------");
SubViewController *svc = [[SubViewController alloc] init];
//正向传值: 最简单的做法, 在子视图控制器中定义属性实例变量接受值
svc.delegate = self;//设置代理
svc.currentTitle = self.navigationItem.title;
[self.navigationController pushViewController:svc animated:YES];
} - (void)sendButtonTitle:(NSString *)title
{
self.navigationItem.title = title;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// SubViewController.h
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @protocol sendTitleReport <NSObject> - (void)sendButtonTitle:(NSString *)title; @end @interface SubViewController : UIViewController //记录当前被选中按钮的标题
@property (nonatomic, copy)NSString *currentTitle;
//防止相互引用
@property (assign, nonatomic) id <sendTitleReport> delegate; @end //
// SubViewController.m
// UI5_UINavigation传值
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SubViewController.h" @interface SubViewController () @end @implementation SubViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
NSArray *titles = @[@"按钮一",@"按钮二",@"按钮三"];
for (int i= 0; i<3; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 100+i*100, self.view.frame.size.width-200, 50);
[btn setTitle:titles[i] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.tag = 200+i;
//设置选中状态
if ([self.currentTitle isEqualToString:btn.currentTitle]) {
btn.selected = YES;
}
[self.view addSubview:btn];
}
} - (void)btnClicked:(UIButton *)btn
{
if([self.delegate respondsToSelector:@selector(sendButtonTitle:)])
{
[self.delegate sendButtonTitle:btn.currentTitle];
}
[self.navigationController popViewControllerAnimated:YES];
} - (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

UI5_UINavigation传值的更多相关文章

  1. mono for android Listview 里面按钮 view Button click 注册方法 并且传值给其他Activity 主要是context

    需求:为Listview的Item里面的按钮Button添加一个事件,单击按钮时通过事件传值并跳转到新的页面. 环境:mono 效果: 布局代码 主布局 <?xml version=" ...

  2. ASP.NET MVC 5 Web编程5 -- 页面传值的方式

    本篇文章将讲述MVC的页面传值方式,具体包括:后端向前端传值(Controller向View传值):前端向后端传值(View向Controller传值):Action与Action之间的传值. 回顾 ...

  3. MUI APP关于页面之间的传值,plusready和自定义事件

    最近在用MUI开发这个APP,发现有时候这个plusready不起作用,表现在,这个页面如果重复打开,这个plusready就进不去,然后上一个页面传过来的值,就没法接收了.这个经过MUI官方确认,是 ...

  4. Android开发之Activity的创建跳转及传值

    在Android系统的江湖中有四大组件:活动(Activity), 服务(Service), 广播接收器(Broadcast Reciver)和内容提供者(Content Provider).今天所介 ...

  5. MVC 传值

    1.ViewBag    Controller:ViewBag.Message = "Hello, Word";    View:@ViewBag.Message   注:View ...

  6. Java传值和传址

    调用函数时,传的参数过去可能是传值,也可能是传址.如果是传值,函数内部的操作对参数的值没有影响:如果是传址,函数内部的操作是对参数指向的内存进行操作,会影响参数的值. Java到底是传值还是传址?用下 ...

  7. Jquery 页面间传值(非QuerryString)

    实现原理: 实现方式不是很复杂,父页面A打开一个子页面 A1,并同时写一个带参数的接收数据函数Receive(result),在A1页面进行逻辑操作,然后调用父页面A的Receive(result)函 ...

  8. Activity往另外一个Activity传值,Fragment获取另外一个Activity里面的值。

    在oneActivity中实现跳转到MainActivity //intent 用来跳转另外一个MainActivity,bundle传值到MainActivity         Intent Ma ...

  9. webform Repeater重复器、地址栏传值、Response

    Repeater: 重复器 <HeaderTemplate></HeaderTemplate> - 头模板:在循环开始时,其内容只会打印一遍 <ItemTemplate& ...

随机推荐

  1. 一个小巧的C++Log输出到文件类 (转)

      http://blog.csdn.net/dpsying/article/details/17122739 有时候需要输出一些程序运行的信息,供我们不需要调试就可以直接查看程序运行状态.所以我们需 ...

  2. innodb_io_capacity >=innodb_lru_scan_depth*inoodb_buffer_pool_instances。与 checkpoint

    innodb_lru_scan_depth:每个缓冲池刷脏页的能力 innodb_io_capacity:  iops inoodb_buffer_pool_instances=8 :缓冲池的个数 . ...

  3. innodb_lru_scan_depth

    innodb_lru_scan_depth是5.6新增加的参数,根据 官方文档 描述,它会影响page cleaner线程每次刷脏页的数量, 这是一个每1秒  loop一次的线程.在Innodb内部, ...

  4. nopCommerce 数据缓存

    为了提高一个系统或网站的性能和IO吞吐量,我们一般都会采用缓存技术.当然NopCommerce也不例外,本文我们就来给大家分析一下nop中Cache缓存相关类设计.核心源码及实现原理. 一.Nop.C ...

  5. 类string的构造函数、拷贝构造函数和析构函数

    原文:http://www.cnblogs.com/Laokong-ServiceStation/archive/2011/04/19/2020402.html   类string的构造函数.拷贝构造 ...

  6. LeetCode6 ZigZag Conversion

    题意: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

  7. TikaEntityProcessor 各种示例

    1. <dataConfig> <dataSource type="BinFileDataSource" /> <script><![CD ...

  8. Amazon 开始接受 Windows 礼品卡预订

    在 8 月微软虚拟货币系统 Microsoft Points 已经正式被真实货币替代,但目前,配套真实货币系统将推出的礼品卡还并没有开始销售.Amazon 上的一则预订显示“Windows 礼品卡”( ...

  9. SQL 必知必会-- 第1课:数据库基础和什么是SQL

    第1课 了解SQL 1 1.1 数据库基础 11.2 什么是SQL 61.3 动手实践 71.4 小结 8 第一课主要是一些概念,具体笔记如下: 1,数据库(database):保存有组织的数据的容器 ...

  10. JSF HelloWord

    JSF(Java Server Faces)是一种用于构建Web应用程序的新标准Java框架.提供了一种以组件为中心来开发Java Web的用户界面的方法,从而简化了开发.   JSF是Java We ...