关闭控制器时将值传递给父控制器
我想将数据发送到parentviewcontroller,但以下代码崩溃了。给我解决方案
Post *vc;
vc.abc =@"Comment Conttroller";
[self.parentViewController dismissModalViewControllerAnimated:YES];
在这里,Post 是我调用 presentViewController:animated:completion
方法的控制器名称。
I want to send data to parentviewcontroller but the following code crashes. Give me the solution
Post *vc;
vc.abc =@"Comment Conttroller";
[self.parentViewController dismissModalViewControllerAnimated:YES];
Here, Post is the controller name from where I am calling the presentViewController:animated:completion
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将其放入您的父控制器中的
viewDidLoad
将以下内容添加到您的子类中,
一旦模型视图被关闭,yourNotificationHandler 就会被执行,并且您作为对象传递的任何内容都将被获取你的父类。请询问是否还需要一些澄清。
Put this in your parent controller in
viewDidLoad
Put following to your child class where
as soon as model view get dismiss yourNotificationHandler get executed and whatever you pass as an objet will get fetch in your parent class. Please ask if still need some clarification.
将其放入 ParentViewController 中的 .h 文件中,
在 ParentViewController Now In Post 视图控制器中创建以下函数
,如下所示:
Now, In secondViewController
viewWillAppear
方法写这个。请检查拼写错误,因为这是我手写的。希望这有帮助。
如果您没有使用 UINavigationContoller ,那么您可以执行类似的操作。
Take this in .h file in ParentViewController
Make below function in ParentViewController
Now In Post view controller do like this:
Now, In secondViewController
viewWillAppear
method write this.Please check spelling mistakes as I've hand written this. Hope this help.
If you are not using
UINavigationContoller
then you can do something like this.vc
似乎没有初始化。您也许可以这样做,
因为您想要影响的视图控制器是parentViewController,您应该能够强制转换并设置abc 属性。
vc
doesn't seem to be initialized.You can probably do this,
Since the view controller you want to affect is the
parentViewController
, you should be able to cast and set theabc
property.