target-action传值
Target-Action传值
实质就是:A页面要给B页面传值,A就提供接口出去,抓A到B内部来,A间接调用自己内部方法(相当于,A把自己内部需 要操作的方法,传到B内来,到B内部进行赋值,这样就不存在訪问不到各自的局部实例变量)
@property (nonatomic,assign)id traget;
@property (nonatomic,assign)SEL action;
[self.traget performSelector:self.action withObject:nil];(是否须要传參数自己定,最多2个)
代码例如以下:
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "UIButton+Create.h"
@interface FirstViewController ()
{
UILabel * _label;
}
@end @implementation FirstViewController
- (void)dealloc
{
[_label release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad]; self.view.backgroundColor = [UIColor redColor];
self.navigationItem.title = @"首页"; _label = [[UILabel alloc]initWithFrame:CGRectMake(50, 80, 200, 30)];
_label.backgroundColor = [UIColor greenColor]; // _label.text = self.text;
[self.view addSubview:_label]; UIButton * button = [UIButton systemButtonWithFrame:CGRectMake(100, 120, 50, 50) title:@"Push" target:self action:@selector(didClickButtonAction)];
[self.view addSubview:button]; // Do any additional setup after loading the view.
} - (void)didClickButtonAction
{ SecondViewController * secondVC = [[SecondViewController alloc]init];
secondVC.target = self;
secondVC.action = @selector(didClick:);
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
} - (void)didClick:(NSString *)text
{
_label.text = text;
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @property (nonatomic,assign)id target;
@property (nonatomic,assign)SEL action;
@end
#import "SecondViewController.h"
#import "FirstViewController.h"
#import "UIButton+Create.h"
@interface SecondViewController ()
{
UITextField * _textField;//创建一个输入框
}
@end
@implementation SecondViewController - (void)dealloc
{
[_textField release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor];
self.navigationItem.title = @"第二页"; _textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 80, 200, 30)];
_textField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:_textField]; UIButton * button = [UIButton systemButtonWithFrame:CGRectMake(100, 120, 50, 50) title:@"Back" target:self action:@selector(didClickButtonAction)];
[self.view addSubview:button]; // Do any additional setup after loading the view.
} - (void)didClickButtonAction
{
[_target performSelector:_action withObject:_textField.text];
[self.navigationController popToRootViewControllerAnimated:YES];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
target-action传值的更多相关文章
- UI基础:target...action设计模式,手势识别器.UIimageview
使用target..action和delegate设计模式可以实现解耦.使代码更加优化. 手势识别器: 手势识别器:是对触摸事件做了封装,无需自己去判断某个手势是否触发,手势识别器本身起到了识别作用, ...
- .net MVC3 页面和 action 传值问题
一.ViewData ViewData ViewBag 的特点和使用场景比较 1. TempData:类型是字典的键值对结构 特点:值只能取一次.保存在Session中,Controller每次执行 ...
- <转> jsp页面向action传值的方法(最后一种简单)
多的不说,直接上代码; struts.xml代码: <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...
- jsp想js,action传值
1.struts2 action如何向JSP的JS函数传值 action中定义变量 public class TestAction extends ActionSupport implements S ...
- struts2中关于jsp页面向action传值出现乱码问题
在JSP页面输入中文并传给后台的时候,常常会出现乱码问题,产生乱码的原因:java在进行传值的时候,默认用的是iso-8859-1的编码形式进行传输,而我们jsp页面常用的则是utf-8的编码形式.所 ...
- Form.action传值问题
通过浏览器地址栏输入url并通过?传递参数请求资源时,?后面的参数叫做 "查询字符串",会触发后台Servlet的doGet(),因为通过浏览器地址栏直接访问的方式是GET方式. ...
- EF5+MVC4系列(12) 在主视图中直接用RenderAction调用子Action,并返回视图(Return View)或者分部视图(Return PartialView); 从主Action传值到子Action使用TempData传值;TempData高级用法
结论: ViewData 适用于 在一次请求中 传递数据 . 比如我们从 主Action 到 主视图, 然后在 主视图中 用 RenderAction 请求子Action的时候,就是算作 一次请求 ...
- struts action和jsp之间的传值
一.jsp对Action传值 提交表单即可,Action的属性必须和表单的标签名字相同 二.Action对jsp传值: (1)利用session,(个人推荐) action中ActionContext ...
- 页面传值总结Block
// AppDelegate.m // 页面传值总结 // // Created by qianfeng on 15/6/13. // Copyright (c) 2015年 qianfeng. Al ...
- iOS开发 — (UINaVigationController)导航控制器,界面传值
UINavigationController 继承于 UIViewController , 以栈的方式管理所 控制的视图控制器 . 至少要有一个被管理的视图控制器 ,这个控制器我们称作导航控制器的根视 ...
随机推荐
- 解决backgroud:transparent在低版本浏览器中的bug
今天在html页面上定义了一个button和一个div,大小相同,button使用绝对定位,覆盖在div上面一层,同时样式设置背景透明(background:transparent). 这样就可以在看 ...
- QT Programming 1
1.控制台输出 helloworld #include<QtCore/QCoreApplication> #include<QDebug> int main(int argc, ...
- SharePoint Server 2010 删除Web应用
SharePoint Server 2010 删除Web应用 因为之前的测试.在SharePointserver创建于非常多Web应用(我是在本机Win7系统上安装的SharePoin ...
- Emacs经常使用快捷键的注意事项
一直用VIM,尝试了好几次Emacs都被它"多得像天上的星星"一样的快捷键给吓倒了.这几天最终下定决心再次尝试. 将它的Tutor练习了一下,顺便对经常使用快捷键做了一下笔记,方便 ...
- Centos 6.4 Linux 相关问题总结
1.中文输入法安装 su root yum install "@Chinese Support" exit 然后设置Input Methord即可. 最后一步:logout,注意是 ...
- Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
近期在知乎看到一句话,保持学习的有一种是你看到了很多其它的牛人,不甘心,真的不甘心. Spring和hibernate整合的时候,jsp页面做展现,发现展现属性出现: org.apache.jaspe ...
- SQLServer 网络协议(一)
SQLserver现在主要的3种协议:Shared Memory.TCP/IP 和 Named Pipe SharedMemory: Shared Memory最快最简单的协议,使用SharedMem ...
- HDU 4149 Magic Potion
意甲冠军: a[i] ^ x = f[i] ( i = 1...8 ) 和 ( a[1] + a[2] + ... + a[8] ) ^ x = f[9] 如今f为已知 求x 思路: 从低位到高位确 ...
- APK ubuntu下 数字签名
Android系统要求每个Android应用程序必需要经过数字签名才可以安装到系统中,也就是说假设一个Android应用程序没有经过数字签名,是没有办法安装到系统中的! Android通过数字签名来标 ...
- libpomelo 增加编译静态库cocos2d-x xcode 工程
离 https://github.com/NetEase/libpomelo 下载最新版本.拉开拉链,静态库 ./pomelo_gyp -DTO=ios ./build_ios ./build_ios ...