简体   繁体   English

如何从拆分视图控制器(ipad后退按钮)中删除视图控制器?

[英]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.

相关问题 如何从 SwiftUI 视图推送到带有后退按钮的 UIKit ViewController - How to push to a UIKit ViewController with back button from a SwiftUI View 如何从呈现的视图控制器上的按钮操作中推动ViewController - How to push viewcontroller from button action on the presented view controller 如何删除viewController中编码的视图按钮? - How to delete of view button coded in viewController? iOS(ipad)分割视图控制器 - iOS (ipad) split view controller 如何在 iPad 的详细视图中选择默认项目? (在拆分视图控制器中) - How to select default item in detail view for iPad? (in Split View Controller) 从tabbar控制器打开带有后退按钮的独立ViewController - Opening a Separate ViewController with back button from a tabbar controller 从标签栏打开导航 controller,并在第一个 ViewController 上使用后退按钮 - Opening a navigation controller from Tabbar with back button on first ViewController 如何在拆分视图控制器中删除TableView行 - How to delete tableview row in split view controller 如何从子视图控制器中更改“后退”按钮文本? - How to change Back button text from within the child view controller? 如何从明细视图中删除数据 controller 并弹回到上一个表视图 controller - How to delete data from the detail view controller and pop back to the previous table view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM