Did you notice that UINavigationBar is not set anymore when creating a UITableView, even after giving it a title or a button?
Now i’m going mad on how to put a navigation bar over my UITableView. It seems really impossible. I tried to add to my tableView a subview with the Navigation Bar, but seems worthless, because when I scroll down, the navigation bar scrolls down as wellm and it shouldn’t.
Any ideas on how to implement it?
EDIT
Well, as always I went on File -> New -> File.. -> UITableView. Then i set a bit of code and when I wrote
self.navigationItem.title = @"MyTitle";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
and tried to test on Simulator, no Navigation Bar appeared.
My init code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"TabTitle";
self.tabBarItem.image = [UIImage imageNamed:@"img.png"];
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
}
return self;
}
I can’t explain why it doesn’t appear anymore. I also tried to create a new project and import my classes from a project where the navigation bar appeared, but same result there too.
EDIT2*
The app is a tabBased application.
Here is the code took from the App delegate used to set up the tabBar.
UIViewController *viewController1, *viewController4;
UITableViewController *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:@"First_iPhone" bundle:nil];
viewController2 = [[Tips alloc] initWithNibName:@"Table" bundle:nil];
viewController3 = [[Favorites alloc] initWithNibName:@"Test_iPhone" bundle:nil];
viewController4 = [[SecondViewController alloc] initWithNibName:@"Second_iPhone" bundle:nil];
}
You are initing an
UITabBarControllerand set 4UIViewControllersas the correspondingUITabbarViewControllers. Since two of them are normalUIViewControntrollerand two areUITableViewControllerthere can not be a navigation bar. You have to load the viewController where you’d like the navbar form aUINavigationController. The correct way would be (assuming vc3 is the one where you’d like the navbar):Then load the vc3NavController instead of viewController3 as the corresponding tab.
So you have: UITabBarController -> UINavigationController -> YourViewController
Maybe Creating a Navigation Interface will help you too.