IOS学习之——界面2传值到界面1(代理方法)
2016-04-15 14:33
357 查看
TRFiristViewController
#import "TRFiristViewController.h" #import "TRSecondViewController.h" @interface TRFiristViewController ()<TRSecondViewDelegate> @property (weak, nonatomic) IBOutlet UILabel *showLabel; @end @implementation TRFiristViewController - (IBAction)gotoSecondVC:(id)sender { TRSecondViewController *vc2=[[TRSecondViewController alloc]init]; vc2.delegate=self; [self presentViewController:vc2 animated:YES completion:nil]; } -(void)secondViewController:(TRSecondViewController *)secondVC message:(NSString *)message{ self.showLabel.text=message; }
#import <UIKit/UIKit.h> //协议中使用了TRSecondController类,这里需要使用@class关键字提前告知有TRSecondController类存在,否则会报不存在TRSecondController类的错误 #import "TRFiristViewController.h" @class TRSecondViewController; //1. 定义一个委托协议,命名为TRSecondViewDelegate @protocol TRSecondViewDelegate <NSObject> - (void)secondViewController:(TRSecondViewController *)secondVC message:(NSString *)message; @end @interface TRSecondViewController : UIViewController //2. 定义delegate属性 @property (nonatomic, weak)id<TRSecondViewDelegate> delegate; @end
@interface TRSecondViewController () @property (weak, nonatomic) IBOutlet UITextField *textField; @end @implementation TRSecondViewController - (IBAction)backToFiristVc:(id)sender { // self.firstVC.content=self.textField.text; [self.delegate secondViewController:self message:self.textField.text]; [self dismissViewControllerAnimated:YES completion:nil]; }
相关文章推荐
- iOS开发系列--数据存取
- ios 之控制器的loadview
- iOS 上传照片到服务器 获取相册和拍照功能的照片 照片压缩上传
- GCD的一些原理
- iOS 获取系统图片
- iOS-上拉刷新,下拉加载-----------详解
- iOS崩溃crash大解析
- iOS 在tableView或scrollView上,消退键盘
- iOS开发之WMPageController的使用
- iOS RunLoop笔记
- iOS开发 引入支付宝 缺少 #include <openssl/asn1.h>
- iOS 版本更新迭代
- iOS开发中的一些图片上传压缩处理
- iOS 相关路径
- iOS常用数学常量宏
- iOS常用的数学函数
- 【iOS学习笔记 16-4-15】正则表达式基础
- ios / % 四舍五入 向上取整(ceil()) 向下取整(floor())
- Masonry
- IOS学习笔记——CocoaPods安装使用