提问人:user2798258 提问时间:1/16/2014 最后编辑:Nayanuser2798258 更新时间:1/16/2014 访问量:439
如何移回视图控制器?
How to move back to the viewcontroller?
问:
有 3 个视图控制器和 .View1,View2
View3
从我必须导航到 .view3
view1
我尝试了以下代码,但它不起作用。
//in View3.m
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
appDelegate.isComingFromCountries = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
//in View2.m
-(void)viewWillAppear:(BOOL)animated
{
if (appDelegate.isComingFromCountries == YES)
{
appDelegate.isComingFromCountries = NO;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
但是这段代码不起作用。我该如何处理?
答:
0赞
Harunmughal
1/16/2014
#1
你可以试试这个: 如果您将一个 viewController 推送到另一个 viewController 并想要向后移动,请使用这个
[self.navigationController popViewControllerAnimated:YES];
如果您正在呈现 viewController,请使用模型并想向后移动,请使用这个
[picker dismissViewControllerAnimated:YES completion:nil];
您也可以尝试此操作,因为首先您需要关闭第三个 viewController,然后是第二个。
UIViewController *viewController = [self parentViewController];
[self dismissModalViewControllerAnimated:NO];
[viewController dismissModalViewControllerAnimated:YES];
2赞
Toseef Khilji
1/16/2014
#2
你可以使用 use 来关闭它,presentingViewController
试试这个 -
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];
A -> B -> C
评论
0赞
Toseef Khilji
1/16/2014
@user2798258:比你能接受的答案,所以它可能对其他人有所帮助。
0赞
Preetam Jadakar
1/16/2014
@Virussmca我已经发布了另一种摆脱此问题的方法,但是您的方法非常简单。
0赞
Nayan
1/16/2014
@Virussmca - 你的意思是如果我有 4 个控制器,比如 A->B->C->D,那么我应该使用 [self.presentingViewController.presentingViewController.presentingViewController...] 导航到 root?
0赞
Jesse
1/16/2014
使用委托更简洁。
0赞
Toseef Khilji
1/16/2014
@NSS:是的,如果您使用 4 个控制器,您必须使用您所说的,我建议最好为此使用 NavigationController,
0赞
codercat
1/16/2014
#3
如果要从一系列以模式方式呈现的视图控制器返回到根视图控制器,则以下代码将在 iOS6 中工作
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
0赞
Mani
1/16/2014
#4
我想,它可能会对你有所帮助。根据您的代码(在评论区),您从第一个视图控制器推送第二个视图控制器,然后从第二个视图控制器中呈现第三个视图控制器。因此,您必须将 delegate 设置为三分之二中的第二。并在第三个 VC 中按如下方式编写代码。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
appDelegate.isComingFromCountries = YES;
[self dismissViewControllerAnimated:YES completion:^{
[self.delegate dismissModal];
};
}
在 SecondVC.m 中
-(void)dismissModal
{
[self.navigationController popViewControllerAnimated:NO];
}
0赞
Shubham
1/16/2014
#5
您也可以像这样从上弹出:view 1
view 3
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[self.navigationController dismissViewControllerAnimated:NO completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
1赞
Preetam Jadakar
1/16/2014
#6
您必须使用延迟方法执行动画,以便主线程应该在 B viewController 中开始执行
[self performSelector:@selector(methodForDissmiss) withObject:nil afterDelay:0.5];
然后在选择器方法中编写 Dismiss 代码以按照您的逻辑工作。
评论