如何在ios应用程序中将uinavigationcontroller加载到uiviewcontroller

时间:2011-12-19 10:48:42

标签: ios4 xcode4 uiviewcontroller uinavigationcontroller

我是IOS开发的新手。现在我为UIViewController实现了一个UINavigationController,但这从视图的顶部给出了一个空白。这是什么原因?如何避免这种差距呢?

这是我的代码

    - (void)viewDidLoad
{
    [self.view setBackgroundColor:[UIColor greenColor]];
    SubClass *subClass=[[SubClass alloc]initWithNibName:@"SubClass" bundle:nil];
    UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:subClass];
    [self.view addSubview:navi.view];
    [super viewDidLoad];
}

以下是输出。

enter image description here

如果有人知道请帮助我。提前谢谢。

1 个答案:

答案 0 :(得分:1)

你可以添加一行

[navi.view setFrame:[self.view bounds]];

 - (void)viewDidLoad
{
    [self.view setBackgroundColor:[UIColor greenColor]];
    SubClass *subClass=[[SubClass alloc]initWithNibName:@"SubClass" bundle:nil];
    UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:subClass];
    [navi.view setFrame: [self.view bounds]];  
    [self.view addSubview:navi.view];
    [super viewDidLoad];
}