iOS代理
2016-04-13 22:47
453 查看
在需要传值的.h中声明代理
在需要传值的.m中,将要进入下一个页面的时候进行代理判断
在接收传值的地方
#import <UIKit/UIKit.h> @protocol SendStringDelegate <NSObject> //传递一个字符串 - (void)sendStringValue:(NSString *)string; @end @interface SecondViewController : UIViewController @property (nonatomic, strong) NSString *inputText; //用来接收前页输入的字符串 @property (nonatomic, assign) id<SendStringDelegate> stringDelegate; @end
在需要传值的.m中,将要进入下一个页面的时候进行代理判断
- (void)clickButton:(UIBarButtonItem *)leftButton{ if (self.mydelegate != nil &&[self.mydelegate respondsToSelector:@selector(senderStingValue:)]) { //代理不能为空 && 代理可以执行协议方法 [self.mydelegate senderStingValue:self.textField.text]; [self.navigationController popViewControllerAnimated:YES]; } }
在接收传值的地方
- (void)clickButton:(UIBarButtonItem *)rightButton{ SecondViewController *secondVC = [[SecondViewController alloc]init]; secondVC.senderString = self.textField.text; // 设置代理 secondVC.mydelegate = self; [self.navigationController pushViewController:secondVC animated:YES]; } // 执行代理方法 - (void)senderStingValue:(NSString *)string{ self.lable.text = string; }
相关文章推荐
- iOS之AFN使用技巧(3)
- iOS 用 SDWebImage 清理图片缓存
- iOS 用 SDWebImage 清理图片缓存
- iOS NSArray 求两个数组的交集 两个数组去重
- iOS学习笔记24-不断进化的屏幕适配
- iOS学习笔记24-不断进化的屏幕适配
- IOS-环信
- iOS知识点汇总
- ios CALayer的Frame,bounds,position,anchorPoint
- iOS 6 Auto Layout NSLayoutConstraint 界面布局
- 第一章 第一个ios应用 笔记
- iOS bundle打包教程
- iOS 通讯录拼音检索
- iOS应用逆向工程
- iOS通讯录iOS9,8,7
- ios可变数组NSMutableArray和不可变数组NSArray的区别
- 解决sencha touch打包后的ios项目顶部状态栏被覆盖问题
- IOS 给View添加阴影效果
- iOS开发笔记:实现对手机号、邮箱输入格式的判断(正则表达式)
- IOS学习之——关闭ios虚拟键盘的几种方法