【UIViewController界面传值】
来源:互联网 发布:追光者 知乎 编辑:程序博客网 时间:2024/06/04 09:01
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
ViewController *v=[[ViewController alloc]init];
self.window.rootViewController=v;
[self.window makeKeyAndVisible];
return YES;
}
ViewController.h
#import <UIKit/UIKit.h>
#import "otherViewController.h"
@interface ViewController : UIViewController<passVaule>
{
UITextField *text;
}
@end
#import "ViewController.h"
#import "otherViewController.h"
@interface ViewController ()
@end
@implementation ViewController
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor greenColor];
text=[[UITextField alloc]initWithFrame:CGRectMake(110, 80, 110, 40)];
text.backgroundColor=[UIColor yellowColor];
[self.view addSubview:text];
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(110, 130, 110, 40)];
btn.backgroundColor=[UIColor yellowColor];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setTitle:@"切换界面" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(shiftTap) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)setString:(NSString *)_str
{
text.text=_str;
}
-(void)shiftTap
{//前提:头文件引入otherviewcontroller.h 且otherviewcontroller.h里声名了str属性
otherViewController *pic=[[otherViewController alloc]init];
pic.str=text.text;
pic.delegate=self;
[self presentViewController:pic animated:YES completion:nil];
}
#import <UIKit/UIKit.h>
@protocol passVaule
-(void)setString:(NSString *)_str;
@end
@interface otherViewController : UIViewController<passVaule>
{
UITextField *text1;
}
@property(strong,nonatomic)NSString *str;
@property(strong,nonatomic)id<passVaule> delegate;
@end
otherViewController.m
#import "otherViewController.h"
@interface otherViewController ()
@end
@implementation otherViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *ima=[UIImage imageNamed:@"start1.jpg"];
[self.view addSubview:[[UIImageView alloc]initWithImage:ima]];
text1=[[UITextField alloc]initWithFrame:CGRectMake(110, 80, 110, 40)];
text1.backgroundColor=[UIColor yellowColor];
//text1.text=self.str;
text1.text=_str;
[self.view addSubview:text1];
UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(110, 130, 110, 40)];
btn1.backgroundColor=[UIColor yellowColor];
[btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn1 setTitle:@"切换界面" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(shiftTap) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1];
}
-(void)shiftTap
{
[self.delegate setString:text1.text];//相当于_str=text1.text
[self dismissViewControllerAnimated:YES completion:nil];//销毁此视图
}
- 【UIViewController界面传值】
- UIViewController界面跳转时的值传递
- UIViewController之间传值:
- UIViewController间的传值
- UIViewController 正向,反向传值
- ios UIViewController 反向传值
- 多个uiviewController之间传值
- UIViewController之间的传值 6种
- UIViewController 间的传值方式
- Swift UIViewController中的delegate方式传值
- Swift UIViewController中的delegate方式传值
- iOS基础界面UIViewController和导航介绍
- UIViewController界面布局的一些坑
- UIViewController生命周期及应用界面切换
- UIViewController的生命周期及界面切换
- UIViewController
- UIViewController
- UIViewController
- Hadoop在Ubuntu下安装教程及伪分布式配置
- 黑马---hashcode与字符串
- Android即时聊天自己封装的QQ录音帮助类.
- Yii框架预定义的组件有哪些?
- Mysql主从同步中的问题及解决方案
- 【UIViewController界面传值】
- hist 绘制直方图函数
- ImageView.adjustViewBounds属性
- Xcode如何打包ipa安装包
- typedef和define的区别
- iOS7.1模拟器似乎不能运行在MacOS_10.11上
- 如何在nginx中使用系统的环境变量(转)
- 有待整理的工作中遇到的问题
- 获取版本号和清除缓存