gpt4 book ai didi

iphone - 自定义导航 Controller iOS 6 的问题

转载 作者:行者123 更新时间:2023-11-29 04:14:35 24 4
gpt4 key购买 nike

我在 appDelegate 中创建了一个自定义导航 Controller :

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

poemsView = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:poemsView] autorelease];
self.navigationController.navigationBarHidden = YES;


self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];

所以问题是我需要来自 viewController 的应用程序午餐,但是如果我将 viewController 设置为 rootviewController ,我的导航 Controller 不会推送导航,反之亦然,如果将我的导航 Controller 设置为 root ,应用程序不会从菜单加载或主视图 Controller 。

最佳答案

为什么要创建 Poemsview 作为导航 Controller 的 Root View Controller ?

如果您想先加载ViewController,则使用以下代码。

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

poemsView = [[[PoemsViewController alloc]initWithNibName:@"PoemsViewController" bundle:nil] autorelease];

self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];

self.navigationController.navigationBarHidden = YES;



self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];

您可以创建另一个导航 Controller 作为 Sub-class of Viewcontroller.

在您的诗歌按钮操作中添加以下内容:

// Create a regular view controller.
PoemViewController *modalViewController = [[[PoemViewController alloc] initWithNibName:@"PoemViewController" bundle:nil] autorelease];

// Create a navigation controller containing the view controller.
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];

// Present the navigation controller as a modal view controller on top of an existing navigation controller
[self presentModalViewController:secondNavigationController animated:YES];

现在您可以从您的 tableview DidselectRowAtindexpath 推送详细 View .

关于iphone - 自定义导航 Controller iOS 6 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13904123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com