简体   繁体   English

如何删除UINavigationViewController

[英]How to remove UINavigationViewController

I have created one navigationController in name_of_my_appAppDelegate.h... After the use I want to remove it from the superview... in my name_of_my_RootViewController I want to call it and remove. 我在name_of_my_appAppDelegate.h中创建了一个navigationController。使用后,我想从超级视图中删除它...在我的name_of_my_RootViewController中,我想调用它并删除它。

How to call it? 怎么称呼它?

In the NewsPadViewController, how to remove the NavigationController when I finished to use it? 在NewsPadViewController中,完成使用后如何删除NavigationController?

#import <UIKit/UIKit.h>

@class NewsPadViewController;

@interface NewsPadAppDelegate : NSObject <UIApplicationDelegate>{
    UIWindow *window;
    UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

and this is the implementation 这是实现

#import "NewsPadAppDelegate.h"
#import "NewsPadViewController.h"


@implementation NewsPadAppDelegate

@synthesize window;
@synthesize navigationController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    [window addSubview:navigationController.view];
    [window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)dealloc
{
    [navigationController release];
    [window release];
    [super dealloc];
}

@end

要删除视图控制器,请删除其视图,如下所示:

[name_of_my_RootViewController.view removeFromSuperview];

Check this out: UINavigationController Class Reference . 检查一下: UINavigationController类参考

You probably want something like this: 你可能想要这样的东西:

[name_of_my_RootViewController popToRootViewControllerAnimated:YES];

Or: 要么:

[name_of_my_RootViewController.view removeFromSuperview];

Or: 要么:

for (UIView *v in self.view.subviews) {
    if ([v isEqual:myView]) {
        [myView removeFromSuperview];
    }
}

Or: 要么:

[((NewsPadAppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController.view removeFromSuperview];

Sounds like you should be presenting the UINavigationController modally in the first place. 听起来您应该首先以模态形式呈现UINavigationController Set up a plain UIViewController called rootViewController and make that visible instead of the navigation controller, then call: 设置一个简单的UIViewController称为rootViewController ,使其可见而不是导航控制器,然后调用:

[rootViewController presentModalViewController:navigationController animated:YES];

And when you're done with it, hit a button on the navigation controller which calls: 完成后,点击导航控制器上的按钮,该按钮将调用:

[self dismissModalViewControllerAnimated:YES];

And you'll go back to the plain UIViewController where you can show the rest of your app. 然后您将回到普通的UIViewController ,在其中可以显示应用程序的其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM