[英]How to delete a viewcontroller from a split view controller (ipad back button )?
I have used the following code for deleting my login page from the navigationcontroller(viewcontrollers)
so that it will not come into the view again when going back(back button). 我使用以下代码从
navigationcontroller(viewcontrollers)
删除我的登录页面,以便在返回(返回按钮)时不会再次进入视图。
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
if ([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[loginViewController class]]&&(VCs.count>=4))
{ [VCs removeObjectAtIndex:[VCs count] - 2];
[VCs removeObjectAtIndex:[VCs count] - 2];
[self.navigationController setViewControllers: VCs];
}
NSLog(@" after :%@",VCs);
}
This works perfectly for i phone.I tried the following code for ipad 这非常适合我的手机。我为ipad尝试了以下代码
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.splitViewController.viewControllers];
NSLog(@" bofore :%@",VCs);
if ([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[loginViewController class]]&&(VCs.count>=4))
{
[VCs removeObjectAtIndex:[VCs count] - 2];
[VCs removeObjectAtIndex:[VCs count] - 2];
[self.navigationController setViewControllers: VCs];
NSLog(@" after :%@",VCs);
}
}
but The content of mutable array VCs in this case is UINavigationControllar
objects. 但是在这种情况下,可变数组VC的内容是
UINavigationControllar
对象。 Anyone know how to do the same this for ipad??Thanks in advance.. 任何人都知道如何为ipad做同样的事情?谢谢。
In iPhone, NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers]; 在iPhone中,NSMutableArray * VCs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers]; Root controller is a navigation controller and so with above statement you would get View Controllers in its stack.
根控制器是一个导航控制器,因此使用上面的语句,您将在其堆栈中获得视图控制器。
In iPad, NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.splitViewController.viewControllers]; 在iPad中,NSMutableArray * VCs = [NSMutableArray arrayWithArray:self.splitViewController.viewControllers]; Root controller is a splitviewcontroller which holds the stack of navigation controllers and so you get Navigation Controllers in the array.
根控制器是一个splitviewcontroller,它包含导航控制器的堆栈,因此您可以在数组中获得导航控制器。 Add below lines of your code and use ViewControllers Array to extract your own viewcontroller.
在代码的下面添加行,并使用ViewControllers Array提取自己的viewcontroller。
UINavigationController *navContoller = self.splitViewController.viewControllers[0]; // Get the Navigation Controller
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray: navController.viewControllers];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.