在当前的 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/