将数据传递回先前分配的UIViewController [英] passing data back to a previously allocated UIViewController

查看:95
本文介绍了将数据传递回先前分配的UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器,然后有一个按钮传递给选项菜单。

I have a view controller that then has a button that passes to an option menu.

当设置选项时,它们需要返回到先前分配的视图控制器。

When options are set they need to be past back to the previously allocated viewcontroller.

如果没有'alloc and init another'对象实例,这怎么可能?

How is this possible without 'alloc and init another' instance of the object?

推荐答案

您可以使用委托协议来实现此目的。第一个视图控制器应该成为第二个视图控制器的委托,然后您可以在选择完成后在第一个视图控制器中调用此委托方法。

You can achieve this by using a delegate protocol. First view controller should become the delegate of the second view controller and then you can call this delegate method in your first view controller once the selection is done.

您可以在objective-c中查找谷歌以实现代表。它非常简单。添加

You can lookup google for implementation of delegates in objective-c. Its pretty simple. Add a

@protocol <delegatename>
<declare delegate method>
@end

在第二个视图控制器中创建一个成员变量,用于分配代理。并在实现委托的类中定义方法。

Create a member variable in the second view controller for assigning the delegate. And define the method in the class implementing the delegate.

这篇关于将数据传递回先前分配的UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆