繁体   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