不确定如何为这个问题命名,但我遇到了这样一个问题:到目前为止,我的应用程序主要在一个带有表格 View 的导航 Controller 中运行。但是现在我正在尝试集成下拉设置菜单,但无法正确完成。
我现在做的和它的工作方式
从一个按钮调用 changeController。 ChangeController 在 appdelegate 中。
- (void) ChangeController
{
self.window.backgroundColor = [UIColor blackColor];
DropDownExample *e = [[DropDownExample alloc] initWithStyle:UITableViewStyleGrouped];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:e];
[e release];
[self.window addSubview:self.navigationController.view];
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
}
但这种方法有一些后果 - 如果按下按钮,则没有转换,设置菜单会立即出现,您无法通过上面的导航栏返回(那里什么都没有)。
那么如何正确地做到这一点?我是 ios 的新手,所以请告诉我如何执行此操作的整个想法。
来自 appdelegate 的 Didfinishlaunchingwithoptions 方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease
];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
TableViewController *tableVC = [[TableViewController alloc] initWithNibName:@"TableView" bundle:nil andType:CONTROLLER_TYPE_FIRST];
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:tableVC];
self.navigationController = navC;
[tableVC release];
[navC release];
self.window.rootViewController = _navigationController;
[self.window makeKeyAndVisible];
return YES;
}
最佳答案
好的,这就是答案。在调用 changeController
changeController
在方法中,写这个。
- (void) ChangeController
{
DropDownExample *e = [[DropDownExample alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:e animated:YES];
[e release];
}
您想要的是在当前 Stack 的顶部插入新的 UIViewController。如果默认情况下顶部有一个导航栏,那么默认情况下会有一个后退按钮,它会弹出该 Controller 。
关于objective-c - 管理导航 Controller / View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062884/