【发布时间】:2014-03-01 21:43:43
【问题描述】:
我有一个 UINavigationGroup 和一个名为 MainViewController 的根视图控制器。在这个MainViewController 中,我将另一个UINavigationController 作为模态调用,如下所示:
- (IBAction)didTapButton:(id)sender {
UINavigationController * someViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"someNavigationController"];
[self.navigationController presentViewController:someViewController animated:YES completion:nil];
}
在这个someNavigationController 中,用户正在经历一些过程,所以导航控制器被一些UIViewControllers 推送。用户完成该过程后,在最后一个名为finalStepViewController 的UIViewController 中,我将关闭模式如下:
[self dismissViewControllerAnimated:YES completion:nil];
模态确实被解除了,用户又回到了最初的MainViewController。
但是,我想将另一个UIViewController 推送到MainViewController 的 NavigationController(例如:表示用户成功完成该过程的视图)。最好在模态被解除之前。
我尝试了以下方法:
1.使用presentingViewController
UIViewController * successViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"successViewController"];
[self.presentingViewController.navigationController successViewController animated:YES];
结果:没有错误,但也没有发生任何事情。
2。委托/协议
- 在
MainViewController.h中导入finalStepViewController.h并附加<finalStepViewControllerDelegate> - 在
MainViewController.m内部添加了一个名为parentMethodThatChildCanCall的方法,可以从finalStepViewController.m调用 -
将以下内容添加到
finalStepViewController.h:@protocol finalStepViewControllerDelegate <NSObject> -(void)parentMethodThatChildCanCall; @end@property (assign) id <finalStepViewControllerDelegate> delegate;和模型中的@synthesize delegate; - 将上述
didTapButtonIBAction 中的delegate 属性设置为someViewController为self。这显示了一个通知错误:Assigning to id<UINavigationControllerDelegate>' from incompatible type UIViewController *const __strong' - 最后在关闭模式之前调用
[self.delegate parentMethodThatChildCanCall]。
结果:除了通知错误,没有失败但没有任何反应,因为没有调用parentMethodThatChildCanCall。
知道我做错了什么/我应该做什么吗?这是我做 Objective-C 的第二周,大多数时候我不知道我在做什么,所以任何帮助/代码都将不胜感激!
谢谢。
【问题讨论】:
标签: ios objective-c uiviewcontroller uinavigationcontroller delegates