简体   繁体   中英

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.

How to call it?

In the NewsPadViewController, how to remove the NavigationController when I finished to use it?

#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 .

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. Set up a plain UIViewController called rootViewController and make that visible instead of the navigation controller, then call:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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