Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:30:44+00:00 2026-06-01T12:30:44+00:00

To give some background, I am making a UINavigationControlled-based blog type app (I suppose

  • 0

To give some background, I am making a UINavigationControlled-based blog type app (I suppose it most closely resembles the iPhone facebook app). Regardless of the view that is currently active, the NavigationBar shows some buttons in its title area, such as Friend Requests and Activity Notifications. In much the same was as the facebook app, clicking these buttons will create a popup view.

Currently, I am doing things in a way that I feel is incredibly inefficient. For every view that is loaded, I am recreating the buttons and adding them to the navigation bar. My code is below:

//Setup the custom middle buttons
UIView *container = [[UIView alloc] init];
container.frame = CGRectMake(0, 0, 80, 44);

// create a button and add it to the container
UIButton *notificationButton = [UIButton buttonWithType:UIButtonTypeCustom];
notificationButton.frame = CGRectMake(0, 0, 35, 44);
[notificationButton addTarget:self 
                       action:@selector(showNotifications:) 
             forControlEvents:UIControlEventTouchUpInside];
[container addSubview:notificationButton];


// add another button to the container
UIButton *friendActivityButton = [UIButton buttonWithType:UIButtonTypeCustom];
friendActivityButton.frame = CGRectMake(45, 0, 35, 44);
[friendActivityButton addTarget:self 
                         action:@selector(showFriendActivity:) 
               forControlEvents:UIControlEventTouchUpInside];
[container addSubview:friendActivityButton];

// Set the titleView to the container view
[self.navigationItem setTitleView:container];
[container release];

Since my app has multiple views and the navigation bar is always visible, it seems silly to keep on recreating the buttons, adding them to a container view, then adding that view to the titleView of the navigation controller.

What would be a better way of achieving the same effect? I was looking into subclassing or creating a category for UINavigationBar and maybe adding in the container view code there. However, I did not know how to make the selectors work in these cases. I also wasnt sure how to get access to the titleView property with a UINavigationBar category.

Any help on this would be great! Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:30:45+00:00Added an answer on June 1, 2026 at 12:30 pm

    I’d recommend just putting the above code in a UIViewController category (or a UIViewController subclass if you can subclass all your view controllers from a single root). Then in viewDidAppear, just call the above code (or put that in the superclass’s viewDidAppear). I think that subclassing UINavigationBar is going to be more trouble than it’s worth.

    If you really want to avoid recreating the buttons (probably no reason to do so, but if it’s important to you for some reason), you can wire the buttons to some singleton object rather than pointing them at self. The singleton could either handle the response directly, forward the message to the active view controller, or post a notification that the active view controller could listen for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a game in Silverlight, and I'd like to give it some background
Can someone give me some info/background info on how I might go about writing
To give some background on my issue: I have 3 tables called Products, Packages,
And if you do, can you give some background information on the implementation and
firstly I'll give some background regarding the situation. I have a website containing approximately
I am building a Recent Activity page just to give some background. Basically this
The Issue Just to give you some background, I'm currently enrolled as a student
Some background: I am making a raycaster, well... was making. But I decided to
My question is stated in the title, to give some background though. I'm helping
Could anyone give me suggestions/advice on making type level integers in OCaml (3.12) supporting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.