【问题标题】:how to call presentViewController with a delegate to self?如何使用委托给 self 调用 presentViewController?
【发布时间】:2014-03-14 23:03:07
【问题描述】:
从当前视图控制器中,我将视图控制器呈现为模型,以从用户那里获取大文本输入。我能够做到这一点,但我不知道如何将输入的文本传递回被调用的视图控制器。
有人可以看一下评论吗?
NotesController *vcNotes = [self.storyboard instantiateViewControllerWithIdentifier:@"FullNotes"];
[self presentViewController:vcNotes animated:YES completion:nil];
【问题讨论】:
标签:
ios
objective-c
delegates
presentviewcontroller
【解决方案1】:
您需要定义一个委托委托协议并将delegate 属性添加到NotesController。
在协议中应该有这样的方法:
- (void)notesController:(NotesController*)nc didFinishWithText:(NSString*)text;
在你的NotesController:
@property (nonatomic, weak) id<NotesControllerDelegate> delegate;
现在,在展示之前,将委托设置为展示视图控制器:
NotesController *vcNotes = [self.storyboard instantiateViewControllerWithIdentifier:@"FullNotes"];
vcNotes.delegate = self;
[self presentViewController:vcNotes animated:YES completion:nil];
现在,在您的笔记控制器中,当您准备好时,调用委托方法:
[self.delegate notesController:self didFinishWithText:self.text];