gpt4 book ai didi

ios - 在 Storyboard 中以模态序列传递数据?

转载 作者:行者123 更新时间:2023-12-01 18:51:09 25 4
gpt4 key购买 nike

我真正的问题是我想通过 将数据从 childViewController 传递到 Storyboard 中的 parentViewController模态序列 .

代码

父 View Controller .h

@property (strong, nonatomic)NSMutableArray *address;

childViewController.m
parentViewController *parent=(parentViewController *)self.presentingViewController;
post.address=@"Hello World";

此代码抛出 异常

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainTabbarViewController setAddress:]: unrecognized selector sent to instance 0x7fa070e6b910'



Storyboard结构

TabbarController-> NavigationController-> parentViewController-> childViewController

先感谢您。

最佳答案

正确的方法是使用委托(delegate)

ChildViewController.h

@protocol ChildDelegate 
- (void)postAddress:(NSString *)address;
@end
@interface ChildViewController
@property (nonAtomic, assign) id<ChildDelegate> delegate;
@end

ChildViewController.m
[self.delegate postAddress:address];

ParentViewController.h
@interface ParentViewController <ChildDelegate>
@end

ParentViewController.m
// presenting childViewController
- (void)presentChildViewController {
ChildViewController *childViewController = [[ChildViewController alloc]init];
childViewController.delegate = self;
[self presentViewController:childViewController animated:YES completion:nil];
}


// delegate method
- (void)postAddress:(NSString *)address{
// add you code here
}

关于ios - 在 Storyboard 中以模态序列传递数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30885140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com