Log*_*gan 13
如果您从父视图传递到子视图控制器,那么只需从父视图设置childViewController的属性.
customChildViewController.someRandomProperty = @"some random value";
[self presentViewController:customChildViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
或者,您可以设置委托
步骤1:在ChildViewController.h文件中设置上面的接口协议
@protocol ChildViewControllerDelegate
- (NSDictionary *) giveMeData;
@end
@interface .....
Run Code Online (Sandbox Code Playgroud)
第2步:在ChildViewController.h接口中创建委托属性
@property (strong, nonatomic) id<ChildViewControllerDelegate>delegate
Run Code Online (Sandbox Code Playgroud)
第3步:在ParentViewController.h中声明委托协议
@interface ParentViewController : UIViewController <ChildViewControllerDelegate>
Run Code Online (Sandbox Code Playgroud)
第4步:在ParentViewController.m中添加此方法:
- (NSDictionary *) giveMeData {
NSMutableDictionary * dataToReturn = [[NSMutableDictionary alloc]init];
dataToReturn[@"some"] = @"random";
dataToReturn[@"data"] = @"here";
return dataToReturn;
}
Run Code Online (Sandbox Code Playgroud)
第5步:在启动childViewController声明委托属性之前.
childViewController.delegate = self;
[self presentViewController:childViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
步骤6:在子视图控制器中,只要您想要数据添加此项
NSMutableDictionary * dataFromParent = [self.delegate giveMeData];
Run Code Online (Sandbox Code Playgroud)
parentVC将运行'giveMeData'并返回NSMutableDictionary(根据您想要的任何数据进行调整)
| 归档时间: |
|
| 查看次数: |
5004 次 |
| 最近记录: |