Adding my own UINavigationBar on Modal table view
I am essentially trying to mimic the contacts app functionality where you click the + button at the top right to make a new contact. I have a navigation based app, and you press the + sign and it loads a modal view that allows you to enter information on a table view (with textfields in the cells). When this view comes up it covers up the navigation bar and I need to put in my own navigation bar with a button to save the info etc.
I added a UINavigationBar* navBar to the view controller class, and initialized it in the view did load function. I changed the view's frame as follows:
CGRect viewFrame = self.view.frame;
CGRect navBarFrame = viewFrame;
navBarFrame.size.height = NAV_BAR_HEIGHT;
viewFrame.origin.y = viewFrame.origin.y + NAV_BAR_HEIGHT;
viewFrame.size.height = viewFrame.size.height - NAV_BAR_HEIGHT;
self.view.frame = viewFrame;
And that works to change the origin but when the view loads, the top part of the table view is covered up by the nav bar (which I show using the following
[self.view.superview addSubview:navBar]; in viewDidAppear).
How come it is covering up the table view? What is the right way to shift the view down? Am I missing something else? Is there a better way to do it? This should be a fairly common thing, but I can't find much online discussing this.
|