Ios 获取UIViewController以推送到另一个控制器
我有一个模态视图控制器,如下所示:Ios 获取UIViewController以推送到另一个控制器,ios,ios7,uiviewcontroller,uinavigationcontroller,Ios,Ios7,Uiviewcontroller,Uinavigationcontroller,我有一个模态视图控制器,如下所示: [self presentViewController:photo animated:YES completion:nil]; 因此,photo是一个模态视图控制器,但当它完成后,我想按如下方式推送到导航视图控制器: [self dismissViewControllerAnimated:NO completion:^{ // UINavigationController *nav = [[UINavigationController alloc]
[self presentViewController:photo animated:YES completion:nil];
因此,photo是一个模态视图控制器,但当它完成后,我想按如下方式推送到导航视图控制器:
[self dismissViewControllerAnimated:NO completion:^{
// UINavigationController *nav = [[UINavigationController alloc] init];
//nav.delegate = self;
ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[_nav pushViewController:profile animated:YES];
}];
nav是照片的视图控制器中也具有委派的属性。仍然不起作用,那么我还缺少什么呢?不要把事情复杂化,因为它可以很容易地完成 在显示照片模式视图控制器的视图控制器中,向其显示如下通知
[self presentViewController:photo animated:YES completion:^{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNextView:) name:@"someNotification" object:nil];
}];
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"someNotification" object:nil];
}];
- (void) pushToNextView:(NSNotification *)notification {
//If you want some value from your notification
//NSDictionary *someValue = notification.object;
[self.navigationController pushViewController:ProfilesViewController animated:YES];
}
然后通过调用该通知来关闭photo modal view控制器,如下所示
[self presentViewController:photo animated:YES completion:^{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNextView:) name:@"someNotification" object:nil];
}];
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"someNotification" object:nil];
}];
- (void) pushToNextView:(NSNotification *)notification {
//If you want some value from your notification
//NSDictionary *someValue = notification.object;
[self.navigationController pushViewController:ProfilesViewController animated:YES];
}
现在你可以像这样推到另一个视图控制器
[self presentViewController:photo animated:YES completion:^{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToNextView:) name:@"someNotification" object:nil];
}];
[self dismissViewControllerAnimated:YES completion:^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"someNotification" object:nil];
}];
- (void) pushToNextView:(NSNotification *)notification {
//If you want some value from your notification
//NSDictionary *someValue = notification.object;
[self.navigationController pushViewController:ProfilesViewController animated:YES];
}
好的,我可以代替object:nil做object:@“value”,然后在通知中获取该值。object?是的,你可以。甚至您也可以在
NSDictionary
中传递多个值。一个问题是推送之前它仍然返回到主视图控制器。我见过应用程序没有这个功能。@chris,是的,没错。应该走了。但是如果您确实不想显示主视图控制器
,只需在显示
和解除
照片模型视图控制器时设置动画:否
。这不会为您提供相同的动画,但可能不会显示主视图控制器。whisper应用程序找到了使用animated=yesWait的方法!不要忘记从ViewController:toViewController:duration:options:animations:completion:的转换,这可能就是您想要的。