簡體   English   中英

如何刪除UINavigationViewController

[英]How to remove UINavigationViewController

我在name_of_my_appAppDelegate.h中創建了一個navigationController。使用后,我想從超級視圖中刪除它...在我的name_of_my_RootViewController中,我想調用它並刪除它。

怎么稱呼它?

在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

這是實現

#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];

檢查一下: UINavigationController類參考

你可能想要這樣的東西:

[name_of_my_RootViewController popToRootViewControllerAnimated:YES];

要么:

[name_of_my_RootViewController.view removeFromSuperview];

要么:

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

要么:

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

聽起來您應該首先以模態形式呈現UINavigationController 設置一個簡單的UIViewController稱為rootViewController ,使其可見而不是導航控制器,然后調用:

[rootViewController presentModalViewController:navigationController animated:YES];

完成后,點擊導航控制器上的按鈕,該按鈕將調用:

[self dismissModalViewControllerAnimated:YES];

然后您將回到普通的UIViewController ,在其中可以顯示應用程序的其余部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM