gpt4 book ai didi

ios - 如何将数据从表单 FormSeetController 传递到 ViewController?

转载 作者:行者123 更新时间:2023-11-29 12:40:51 25 4
gpt4 key购买 nike

我正在尝试使用这个包:

https://github.com/m1entus/MZFormSheetController

现在我的问题是,在关闭 formSheet 后,我​​试图在 FormSeetController 与 ViewController 之间传递数据。

这里是我到目前为止尝试过的:在创建表单的按钮中的 ViewController 中:

formSheet.didDismissCompletionHandler = ^(UIViewController *vc){
// maybe i can use UIViewController *vc as my SearchGardenView (form Sheet), but how?

[self formSheetDidDismissed]; // here i tryin to get the kidGardenID but its always nil;
};

这是在 FormSeetController 中:

    AddKid *kid = [[AddKid alloc]init];
NSArray *temp = [_responseDict valueForKey:@"ID"];
kid.kidGardenID = [temp objectAtIndex:indexPath.row];

[self mz_dismissFormSheetControllerAnimated:YES completionHandler:^(MZFormSheetController *formSheetController) {

//this block dismiss the formSheet.
}];

我需要将“kidGardenID”传递给 ViewController,但它始终为 nil,即使在我给它一个值之后,如上面的代码所示。可能是因为 ViewController 已经加载,而当我从 fortSheet 返回时它没有再次加载?

我需要找到一种方法来传递这些数据,你能帮帮我吗?

编辑我尝试使用委托(delegate)但没有成功,委托(delegate)未被调用。这是我的委托(delegate)代码:

设置委托(delegate)(ViewControllerB)

@class SearchGardenTable;
@protocol SearchGardenDelegate <NSObject>
- (void)addItemViewController:(SearchGardenTable *)controller didFinishWithGardenID:(NSString *)gardenID gardenName:(NSString*)gardenName andCityName:(NSString*)cityName;
@end

@interface SearchGardenTable : UITableViewController

@property (nonatomic, weak) id <SearchGardenDelegate> delegate;
@end

告诉 VC B VC A 是它的委托(delegate):

 self.searchGarden.delegate = self; // in VC A viewDidLoad.

设置我想从 VC B 传回 VC A 的参数:

    _kidGaedenID  = [temp objectAtIndex:indexPath.row];
_kidGardenName = [temp1 objectAtIndex:indexPath.row];


[self.delegate addItemViewController:self didFinishWithGardenID:_kidGaedenID gardenName:_kidGardenName andCityName:_kidCityName];

在 VC A 实现协议(protocol)方法:

- (void)addItemViewController:(SearchGardenTable *)controller didFinishWithGardenID:(NSString *)gardenID gardenName:(NSString*)gardenName andCityName:(NSString*)cityName
{
_kidGardenID = gardenID;
_gardenName.text = gardenName;
_kidCity.text = cityName;

}

最佳答案

您可以尝试使用 willDismissCompletionHandler。这是在 MZFormSheetController.h 文件中定义的。将参数 presentedViewController 键入您的 View Controller (我假设是 AddKid),您可以在此处访问 AddKit 类的属性。

@property (nonatomic, copy) MZFormSheetCompletionHandler willDismissCompletionHandler;

formsheet.willDismissCompletionHandler = ^(UIViewController *presentedViewController){
((AddKid*)presentedViewController).kidGardenID // should be accessible now.

};

关于ios - 如何将数据从表单 FormSeetController 传递到 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24982712/

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