方式一:通过定义一个实体类传值 (从ViewController1 跳转至 ViewController2)

1、定义实体类NotificationEntity

.h声明文件

#import <Foundation/Foundation.h>

@interface NotificationEntity : NSObject

{

}

@property (nonatomic,retain) NSString *strTitle; //参数一

@property (nonatomic,retain) NSString *strContent; // 参数二

@property (nonatomic,retain) NSString *strUrl; //参数三

@end

.m实现文件

#import "NotificationEntity.h"

@implementation NotificationEntity

@synthesize strTitle=_strTitle;

@synthesize strContent=_strContent;

@synthesize strUrl=_strUrl;

@end

2、在ViewController2中

在.h文件中声明实体类NotificationEntity为ViewController2的类成员变量:

@property (retain,nonatomic) NotificationEntity *mNotifEntity;

在.m文件中通过@synthesize为成员变量mNotifEntity合成存取方法:

@synthesize mNotifEntity=_mNotifEntity;

3、在ViewController1中实现跳转并传递参数

// 组装实体类的实例变量

NotificationEntity *mNotificationEntity = [[NotificationEntity alloc] init];

[mNotificationEntity setStrTitle:strTitle];

[mNotificationEntity setStrContent:strContent];

[mNotificationEntity setStrUrl:strUrl];

// 实例化ViewController2

ViewController2 *viewController2 = [[ViewController2 alloc] init];

// 注入参数

[viewController2 setMNotifEntity:mNotificationEntity];

// 跳转

[self.window.rootViewController presentModalViewController:viewController2 animated:YES];

4、在ViewController2中接收参数:

- (void)viewDidLoad

{

[super viewDidLoad];

[self.lblTitle setText:[self.mNotifEntity strTitle]];

[self.lblContent setText:[self.mNotifEntity strContent]];

}

5、在ViewController2中加入返回ViewController1的事件:

- (IBAction)backOff:(id)sender

{

[self dismissModalViewControllerAnimated:YES];

}

在好多博文中看到@synthesize,下面对这个标志做一下说明:

1.在Xcode4.5及以后的版本中,可以省略@synthesize ,编译器会自动帮你加上getter 和 setter 方法的实现,并且默认会去访问

_age这个成员变量,如果找不到_age这个成员变量,会自动生成一个叫做 _age的私有成员变量。

from :http://blog.csdn.net/wanggsx918/article/details/19546987?utm_source=tuicool&utm_medium=referral

最新文章

  1. C# 序列化反序列化
  2. Unity Standard Assets 简介之 2D
  3. python 代码片段17
  4. android应用商店完整版源码
  5. Enum枚举 简单的使用
  6. Poj 1054 The Troublesome Frog / OpenJudge 2812 恼人的青蛙
  7. JavaScript- The Good Parts Chapter 5 Inheritance
  8. AD RMS Bulk Protection Tool 批量加密解密office文档
  9. phpcms get标签说明
  10. nginx环境下搭建nagios 3.5.0,及配置pnp4nagios画图
  11. jquery keyup 在IOS设备上输入中文时不触发
  12. android之IntentFilter的用法_Intent.ACTION_TIME_TICK在manifest.xml不起作用
  13. C语言顺序栈实现
  14. iOS 旋转
  15. JS学习一
  16. Ajax.html:35 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user&#39;s experience. For more help, check https://xhr.spec.whatwg.org
  17. 算法与数据结构(七) AOV网的拓扑排序(Swift版)
  18. 【Oracle-PLsql】使用存储过程,利用table集合类型开发复杂业务报表
  19. 【整理】LINUX下使用CMAKE安装MYSQL
  20. RTCM32编解码中的一些概念及相关文献阅读

热门文章

  1. Software - (转)Winform 程序捕获全局异常
  2. Open-source Tutorial - NLog
  3. SQL依据特殊符号分批截取字符串(案例)
  4. &quot;Mysql has gone away&quot;的几种可能
  5. js 读本地文件
  6. 动画重定向技术分析和Unity中的应用
  7. Noip2016day1 玩具迷题toy
  8. Tyvj2017清北冬令营入学测试
  9. [Xcode 实际操作]六、媒体与动画-(15)使用AudioPlayer播放音乐
  10. IT兄弟连 JavaWeb教程 JSON和JSON字符串