2012-12-16 57 views
0

我在的appDelegate创建自定义导航控制器:问题与自定义导航控制器的iOS 6

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的,我的导航控制器不会推导航,反之亦然,如果将我的导航控制器设置为根,则不会从菜单或主视图控制器加载应用程序。

+0

你是如何定制导航栏的?典型的解决方案包括使用'appearance'自定义标准导航控制器的外观,在'UINavigationBar'上放置一个类别并替换它的'drawRect'。你能解释你想要在你的定制中做什么吗?你通常不想为UINavigationController子类(不是你所做的就是这样),但我不清楚你想做什么。建议将取决于您试图达到的效果。 – Rob

+0

ViewController的目的是什么?如果你使用它作为临时的东西,比如登录或启动屏幕,我会从PoemsViewController中以模态方式呈现它。 – rdelmar

回答

1

为什么你创建Poemsview作为导航控制器的rootviewcontroller?

如果您想首先加载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]; 

您可以创建另一个导航控制器作为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

+0

我知道,但然后导航控制器不会在详细viewViewController例如因为它的根没有定义! – Momi

+0

你检查过我的代码吗'self.viewcontroller'是'rootviewcontroller'。 –

+0

他是对的,你的rootViewController在这里是导航控制器,它在堆栈底部有self.viewController。它应该工作,试试看。 –