码迷,mamicode.com
首页 > 移动开发 > 详细

IOS下viewcontroller之间传递数据

时间:2014-12-25 09:52:13      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

使用场景

A中调用B页面,在B中用户做了处理后,将数据回传给A

第一步,新建passValueDelegate.h

#import <Foundation/Foundation.h>

@protocol PassSelectDelegate <NSObject>

-(void)passValue:(NSDictionary *)value;

@end
 
第二步,第一个viewcontroller中遵守协议
ApplyController.h
#import "PassSelectDelegate.h"

@interface ApplyController : UIViewController<PassSelectDelegate, UITextFieldDelegate>
 
在ApplyController.m中实现协议
-(void)passDelegate:(NSDictionary *)value
{
  NSLog("value:%@", value);
}
注意:在从第一个ViewController跳转到第二个ViewController的过程中,指定代理是在第一个viewcontroller中实现的
SecondViewController *viewcontroller = [SecondViewController alloc] init];
viewController.delegate = self;
[self.navigationController pushViewController:viewController animated:YES];
 
第三步,在第二个viewcontroller中调用这个协议
SecondViewcontroller.h
#import "passSelectDelegate.h"
@property(nonatomic,assign) NSObject<PassSelectDelegate> *delegate;
 
SecondViewcontroller.m
-(void)confirmSelect:(NSDictionary *)selectValue
{
    [self.delegate passValue:selectValue];
    [self.navigationController popViewControllerAnimated:YES];
}
 
[本博文是记录传递参数原理,直接不知代码可能不能执行]
 

IOS下viewcontroller之间传递数据

标签:

原文地址:http://www.cnblogs.com/progfun/p/4183878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!