strange space issue when adding Kal as subview

466 Views Asked by At

There's too much black space between the Kalendar and the navigation bar. Here's a picture of what I'm talking about:

kalview

I'm calling the code from ViewDidLoad of a ViewController that I have in my storyboard:

- (void) viewDidLoad {
    KalViewController *calendar = [[KalViewController alloc] init];
    [self.view addSubview:calendar.view];
}

I'm just learning to use Kal. Maybe I'm going about incorporating it in the wrong way. I sure do like using the storyboard to link up my views so my viewcontroller includes "Kal.h" and I instantiate as shown in the code above. I tried to make the viewcontroller a subclass of KalViewController but that didn't work.

Maybe there's a more elegant way of incorporating Kal into a hierarchy of storyboarded view controllers?

2

There are 2 best solutions below

0
On

Just add the following:

[[self navigationController] initWithRootViewController:calendar];
[[calendar navigationItem] setHidesBackButton:YES];

and it should do the trick. The second line is being used to hide the "Back" button that otherwise becomes visible, but for me it's a single screen app, you may or may not want to use it.

0
On

I used the exact same code as you initially did ACB, had the exact same problem but I also had included [self addChildViewController:calendar]; after the creation of the calendar view.

What does this code do? [self addChildViewController:calendar];

I understand it "adds a child view controller" but what is REALLY going on.... and should I need this? Apparently not because you didn't, and I just compiled my code without it and there was no difference.

Overall code:

KalViewController *calendar = [[KalViewController alloc] init];

[self.view addSubview:calendar.view];

//[self addChildViewController:calendar];