执行此操作的标准方法是使用委托。
在您的 UIInputViewController 中添加一个新的委托协议以及您的委托的属性。
然后在您的 CallerUIViewController 中实现委托。然后,在您关闭模态视图控制器之前,您可以回调您的委托。
所以你的InputViewController可能看起来像这样:
@protocol InputViewControllerDelegate;
@interface InputViewControllerDelegate : UIViewController {
}
@property (nonatomic, assign) id <InputViewControllerDelegate> delegate;
@end
@protocol InputViewControllerDelegate
- (void)didFinishWithInputView:(NSString *)stringValue;
@end
关闭模态视图的方法如下所示:
-(void)dismissSelf
{
[self.delegate didFinishWithInputView:@"MY STRING VALUE"];
[self dismissModalViewControllerAnimated:YES];
}
然后在 CallerUIViewController 中,您将实现 InputViewControllerDelegate 和 didFinishWithInputView 方法。
Caller UIViewController 标头看起来像:
@interface CallerUIViewController : UIViewController <InputViewControllerDelegate> {
}
你的 didFinishWithInputView 方法将实现如下:
- (void)didFinishWithInputView:(NSString *)stringValue
{
// This method will be called by the InputViewController just before it is dismissed
}
在呈现 InputViewController 之前,您需要将委托设置为 self。
-(void)showInputViewController
{
InputViewController *inputVC = [[InputViewController alloc] init];
inputVC.delegate = self;
[self presentModalViewController:inputVC animated:YES];
[inputVC release];
}