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 8480167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:13:22+00:00 2026-06-10T19:13:22+00:00

I have successfully added a rightBarButtonItem to my navigationBar , but I would prefer

  • 0

I have successfully added a rightBarButtonItem to my navigationBar, but I would prefer to only have the code to do so show up once rather than once per type of ViewController. Here’s my current setup:

                -->TVC
               |
NVC--->TVC--->TVC--->VC

So far I’ve subclassed UITableViewController and moved my code for adding the button into my subclass. All 3 of my TableViewControllers are set to that subclass and it works perfectly.

However now I need my lone ViewController to also show the button, but I don’t know how to accomplish this without duplicating the code from my TVC subclass. Is subclassing the right answer or do I need a different approach?

Edits:

@CarlVeazey – Sure, I call it from the viewDidLoad function.

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"BETA" style:UIBarButtonItemStylePlain target:self action:@selector(betaPressed)];
  • 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-10T19:13:23+00:00Added an answer on June 10, 2026 at 7:13 pm

    Do a pull-up refactor into a UIViewController category. If your project already has one, just add this code there, otherwise press cmd-N in Xcode to create a new file and choose “Objective-C Category” and enter UIViewController in the “Category On” field.

    In the interface add this method declaration:

    - (void)onfConfigureRightNavigationBarButton;
    

    And in the implementation add this method implementation:

    - (void)onfConfigureRightNavigationBarButton
    {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"BETA" 
                                                                                  style:UIBarButtonItemStylePlain 
                                                                                 target:self 
                                                                                 action:@selector(betaPressed)];
    }
    

    Then in any UIViewController subclass you can import your category header and call this method. You may also wish to add to your category an empty implementation of betaPressed:.

    BTW, ONF is the prefix I use for non-work coding so use whatever prefix already is in your project, or none at all if you’re not concerned with category name collisions.

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

Sidebar

Related Questions

I have a png icon, it's added successfully in my project, but not included
I have successfully added a dynamic library to a program, but when I try
I am building an Android app using phoneGap and I have successfully added the
Have successfully gotten the csrf middleware working in express as per previous SO questions.
i have successfully added input element into div, which looks like this : $(document).ready(function()
I have successfully added and used a Get action in my new REST-service in
I have a 3rd party .dll that I have successfully added as a reference
I've just followed this example from Wordpress and I have successfully added an extra
Has anyone of you successfully added a lexer to scintilla? I have been following
I have successfully added the font Arial to TCPDF , however the filesize is

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.