0

I want to change my table view navigation bar background image to some png, i created the nav bar png with the exact sizes of a default nav bar (I checked in interface builder).

This is my code (in my table view controller class, viewDidLoad method):

once i tried this one:

UIImageView *backImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nav.png"]];
[self.navigationController.navigationBar addSubview:backImgView];
Shouldn't this work..?

and the other was this one:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav.png"] forBarMetrics:UIBarMetricsDefault];

both were from people here in stack overflow trying to help me solve this.

this is my table view settings in the interface builder if this help:

enter image description here enter image description here

the top one is what i suppose to get and the bottom one is what im getting:

enter image description here

thanks!

nick shmick
  • 905
  • 1
  • 9
  • 25
  • Are you presenting that UIViewController as a Modal or PopOver view? – Benjamin Jimenez Apr 01 '15 at 21:36
  • @BenjaminJimenez popOver – nick shmick Apr 01 '15 at 21:42
  • Not sure if it would work but have you tried changing the bar style? http://stackoverflow.com/questions/19095195/ios7-navigatinbar-tintcolor-change-in-popover, see the first answer, maybe making it translucent – Benjamin Jimenez Apr 01 '15 at 21:51
  • You say you are using a popover. Are you actually putting a UINavigationController in your popover with the problem controller as the root? If not then self.navigationController will be nil. Solution is to embed a UINavigationController in. – Rory McKinnel Apr 01 '15 at 22:00
  • @RoryMcKinnel I have A: view controller that im popping over from. B: a view controller that im popping to (which is a table view controller and in its vieDidLoad im assigning the bg for the nav.) I dont any more code for it in the B view controller. what did you mean I need to do? – nick shmick Apr 01 '15 at 22:14
  • nothing work's so far :/ – nick shmick Apr 01 '15 at 22:20
  • self.navigationController is a utility property whose getter finds the navigation controller self is in the navigation stack of. So you need to create a UINavigationController whose root is B. You then need to popover to the UINavigationController and not B. In storyboard you can select B and on the Editor menu select EmbedIn -> UINavigationController. Or if using code, where you create the popover use `UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:B]` and then put `nav` in the popover rather than B. – Rory McKinnel Apr 01 '15 at 22:24
  • StackTableViewController *stackViewController = [[StackTableViewController 'alloc]initWithNibName:@"StackTableViewController" bundle:nil]; UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:stackViewController]; [self.navigationController presentViewController:navigationController animated:YES completion:nil]; dont know how to format it to be a code view @RoryMcKinnel – nick shmick Apr 01 '15 at 22:32
  • this is how im going from A view controller to B view controller @RoryMcKinnel – nick shmick Apr 01 '15 at 22:33
  • That looks ok to me. Did you add your own navigation bar on your B controller originally? If so your problem has probably been not setting its background. If you did add your own to B originally you should be setting the background of that one (i.e. you need an IBOutlet for it so you can do `[self.myNavBar setBackgroundImage:[UIImage imageNamed:@"nav.png"] forBarMetrics:UIBarMetricsDefault];`. – Rory McKinnel Apr 01 '15 at 22:53

0 Answers0