Search code examples
ios4xcode4uiviewcontrolleruinavigationcontroller

how can load uinavigationcontroller to uiviewcontroller in ios application


I am new in IOS development .Now i implement a UINavigationController to a UIViewController, but this give a gap from the top of the view .What is the reason for this? and How can avoid this gap?

This is My code

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

The Following is the Output.

enter image description here

If anybody know please help me. Thanks in advance.


Solution

  • U can add one more line

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