如何调用presentViewController与委托给自己?

时间:2014-03-14 23:03:08

标签: ios objective-c delegates presentviewcontroller

从当前视图控制器,我将一个viewController呈现为Model,以从用户获取大量文本输入。我能够这样做,但我不知道如何将输入的文本传递回被叫视图控制器。

有人可以看一看并发表评论吗?

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

1 个答案:

答案 0 :(得分: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];