从 UIViewController 返回 NSString
我想从一个名为 InputUIViewController 的 UIViewController 返回一个 NSString *
到之前启动了 InputUIViewController 的 UIViewController (名为 CallerUIViewController)。我想在 InputUIViewController 调用之前或调用时执行此操作:
[selfmissModelViewControllerAnimated:YES];
有标准方法可以执行此操作吗?
I want to return a NSString *
from a UIViewController, called InputUIViewController, to the previous UIViewController, called CallerUIViewController, which started InputUIViewController. I want to do it just before or when InputUIViewController calls:
[self dismissModelViewControllerAnimated:YES];
Is there a standard way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作的标准方法是使用委托。
在您的 InputViewController 中添加一个新的委托协议以及您的委托的属性。
然后在您的 CallerUIViewController 中实现委托。然后,在您关闭模态视图控制器之前,您可以回调您的委托。
所以你的InputViewController可能看起来像这样:
关闭模式视图的方法看起来像这样:
然后在你的CallerUIViewController中你将实现InputViewControllerDelegate和didFinishWithInputView方法。
CallerUIViewController 标头看起来像:
并且您的 didFinishWithInputView 方法将实现类似:
在呈现 InputViewController 之前,您会将委托设置为 self。
The standard way to do this would be to use a delegate.
In your InputViewController add a new delegate protocal, and a property for your delegate.
Then in your CallerUIViewController implement the delegate. Then just before your dismiss the modal view controller you can call back to your delegate.
So your InputViewController might look like this:
The method that dismisses the modal view would look something like this:
Then in your CallerUIViewController you would implement the InputViewControllerDelegate and the didFinishWithInputView method.
The CallerUIViewController header would look something like:
and your didFinishWithInputView method would be implemented something like:
Just before your present the InputViewController you would set the delegate to self.
您可以通过简单地在前一个视图控制器中创建一个
NSString
对象作为property
来完成此操作,然后在第二个视图中调用dismissModelViewControllerAnimated
然后在它分配值之前到上一个视图控制器属性
。这可能会帮助你 -使用 Objective-C 在类之间传递数据
You can do this by simply creating a
NSString
object asproperty
in prvious view controller and when in second view you calldismissModelViewControllerAnimated
then before it assign value to previous view controllerproperty
. This might help you -Passing data between classes using Objective-C