ios - 如何使用委托(delegate)给自己调用 presentViewController?

标签 ios objective-c delegates presentviewcontroller

在当前的 View Controller 中,我将 viewController 作为模型呈现,以从用户那里获取大量文本输入。我能够做到这一点,但我不知道如何将输入的文本传递回调用的 View Controller 。

有人可以看看和评论吗?

NotesController *vcNotes =  [self.storyboard instantiateViewControllerWithIdentifier:@"FullNotes"];
[self presentViewController:vcNotes animated:YES completion:nil];

最佳答案

您需要定义委托(delegate)委托(delegate)协议(protocol)并添加 delegate属性(property)NotesController .

在协议(protocol)中,应该有一个方法,例如:

- (void)notesController:(NotesController*)nc didFinishWithText:(NSString*)text;

在您的 NotesController 中:

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

现在,在呈现之前,将委托(delegate)设置为呈现 View Controller :

NotesController *vcNotes =  [self.storyboard instantiateViewControllerWithIdentifier:@"FullNotes"];
vcNotes.delegate = self;
[self presentViewController:vcNotes animated:YES completion:nil];

现在,在您的笔记 Controller 中,当您准备好时,调用委托(delegate)方法:

[self.delegate notesController:self didFinishWithText:self.text];

关于ios - 如何使用委托(delegate)给自己调用 presentViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22417326/

相关文章:

ios - IOKit ARM7* 二进制文件,它位于 iPhone 设备上的什么位置?

ios - CAKeyframeAnimation 在 UIImageView 中具有不同的动画持续时间值

objective-c - 如何在iOS 6 的UICollectionView 中实现无限水平和垂直滚动?

c# - C# 中匿名 lambda 函数的 C++ 捕获子句等效项

ios - UIImageView 设置为 ASpectFill 时出现内容模式问题

ios - 具有两个物理体的节点

ios - 带分割 View 的MMDrawerController

ios - 拖动分隔符以调整 UIView 的大小

ios - 从 Swift iOS 中的模态视图中获取值(value)

iphone - 委托(delegate)和协议(protocol)无法正常工作