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).
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
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.
Anyone know how to do the same this for ipad??Thanks in advance..
In 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]; Root controller is a splitviewcontroller which holds the stack of navigation controllers and so you get Navigation Controllers in the array. Add below lines of your code and use ViewControllers Array to extract your own viewcontroller.
UINavigationController *navContoller = self.splitViewController.viewControllers[0]; // Get the Navigation Controller
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray: navController.viewControllers];