Note that there are some explanatory texts on larger screens.

plurals
  1. POOverwriting UINavigationBar to set a default titleView
    primarykey
    data
    text
    <p>What I want to do is a navigation bar with a image on it. I have a tab controller on my main view, and inside each tab I have a UINavigationController. From inside the UIViewController that my tab/navigationController calls, I could set the titleView without much problem, doing this inside the viewDidLoad method:</p> <pre><code>self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mylogo.png"]] autorelease]; </code></pre> <p>But, I want to replace all titles in my navigationBar for this view, and it seems ugly to repeat this everywhere. So I did this on the delegate (after linking all the Outlet stuff)</p> <pre><code>self.tabOneNavController.navigationBar.topItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mylogo.png"]] autorelease]; </code></pre> <p>Again, it worked! ok, I'm almost getting there. But the point is, I've 5 tabs and all of them have navigationControllers inside. I reduced the code repetition from every internal view to only 5 times, but it still. It requires that I do that for the NavController of each tab.</p> <p>Then I tried to extend the UINavigationBar to create my own, where I could set this in the initializer, and use it in the interface builder as the object class. But it doesn't seem to work. Here is what I did:</p> <pre><code>@implementation MyNavigationBar - (id)init { self = [super self]; self.tintColor = [UIColor greenColor]; self.topItem.title = @"testing please work"; return self; } @end </code></pre> <p>in the interface file MyNavigationBar inherits from UINavigationBar. But this didn't work. Should I overwrite other method? which one? is this a good practice? I'm not even sure if I should add one navigationBar for each tab, as I said, I have tabs and I want to have a navigation bar / navigate inside them. By now, after a near death experience trying to figure out how the interface builder / outlets and classes work, the code is working, I just would like to make unglify it.</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload