【问题标题】:how can load uinavigationcontroller to uiviewcontroller in ios application如何在 ios 应用程序中将 uinavigationcontroller 加载到 uiviewcontroller
【发布时间】:2011-12-19 10:48:41
【问题描述】:

我是 IOS 开发的新手。现在我将 UINavigationController 实现为 UIViewController,但这与视图顶部有差距。这是什么原因?以及如何避免这种差距?

这是我的代码

    - (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];
}

以下是输出。

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

【问题讨论】:

    标签: ios4 xcode4 uiviewcontroller uinavigationcontroller


    【解决方案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];
    }
    

    【讨论】:

    • 或者你必须像这样为 navi.view 设置框架 [navi.view setFrame: CGRectMake(0, 0, 320, 480)];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 2017-02-18
    • 2014-04-03
    • 2019-10-16
    • 1970-01-01
    • 2013-08-11
    相关资源
    最近更新 更多