我在name_of_my_appAppDelegate.h中创建了一个navigationController ... 使用后我想从superview中删除它... 在我的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
答案 0 :(得分:1)
要删除视图控制器,请删除其视图,如下所示:
[name_of_my_RootViewController.view removeFromSuperview];
答案 1 :(得分:1)
检查出来:UINavigationController Class Reference。
你可能想要这样的东西:
[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];
答案 2 :(得分:1)
听起来你应该首先以模态方式呈现UINavigationController
。设置一个名为UIViewController
的普通rootViewController
并使其可见而不是导航控制器,然后调用:
[rootViewController presentModalViewController:navigationController animated:YES];
当你完成它后,点击导航控制器上的一个按钮,该按钮调用:
[self dismissModalViewControllerAnimated:YES];
然后您将返回普通UIViewController
,您可以在其中显示应用的其余部分。