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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:08:47+00:00 2026-05-25T21:08:47+00:00

I have build a view with a UIToolbar which is working great. This toolbar

  • 0

I have build a view with a UIToolbar which is working great.

This toolbar will be appearing right across the app, and right now I am copy/pasting the code into lots of different files.

I do not want to repeat myself, and am looking to create a helper file that will include the toolbar setup and the methods linked to the toolbar in every file I need.

I’ve tried putting the following code into a .h .m file and inheriting from UIView, but there is a problem because there is a reference to self.navigiationItem

Is there a way that I can create a common Objective C file that will have all the code and methods I want to use?

Thanks.

- (void)viewDidLoad
   // ... 

    // appears in viewDidLoad
     // ---- TOOLBAR -----------//

        UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100.0, 44.01f)];
        //[toolbar setBackgroundColor:[UIColor blackColor]];
        //[toolbar setTintColor:[UIColor redColor]];
        //[toolbar.layer setBorderColor:[[UIColor redColor] CGColor]];

        // Bar buttons

        UIBarButtonItem *barReloadBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(btnReload:)];

        [barReloadBtn setStyle:UIBarButtonItemStyleBordered];

        // Profile bar button
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"111-user" ofType:@"png"]];

        UIBarButtonItem *barProfileBtn = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(btnProfile:)];


        // Button array

        NSMutableArray *buttons = [[NSMutableArray alloc] init]; 

        [buttons addObject:barProfileBtn];
        [buttons addObject:barReloadBtn];


        [toolbar setItems:buttons];

        // Set nav items

        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];

        // memory cleanup
        [image release];
        [buttons release];
        [barReloadBtn release];
        [barProfileBtn release];    
        [toolbar release];


        // ---- /TOOLBAR -----------//
    }



    #pragma mark - IBActions

    -(IBAction) btnProfile:(id)sender
    {
        UserProfileVC *userProfileVC = [[UserProfileVC alloc] initWithNibName:@"UserProfileVC" bundle:[NSBundle mainBundle]];

        UINavigationController *tmpNavCon = [[UINavigationController alloc] initWithRootViewController:userProfileVC];

        [self.navigationController presentModalViewController:tmpNavCon animated:YES];

        [tmpNavCon release];
        [userProfileVC release];
    }

    -(IBAction) btnReload:(id)sender
    {
        NSLog(@"Not done yet");
    }
  • 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-05-25T21:08:48+00:00Added an answer on May 25, 2026 at 9:08 pm

    navigationItem is a property of UIViewController, not UIView. If you’ve got common functionality like this, I would inherit from UIViewController, add your custom logic to viewDidLoad (or wherever is appropriate) and then inherit your view controllers from that class. Just make sure you call [super viewDidLoad] from your subclasses’ implementations of viewDidLoad.

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

Sidebar

Related Questions

I want to build a view, which will contain an injected view into a
Right now, I have a do loop for a task model in my view:
I have an iPhone app which was built using a standard UITabBarController. This app
I have a method helper which reads files and directory and build html view.
I have a situation where I build a view with a table and another
Why is using '*' to build a view bad ? Suppose that you have
I have a Monthly Status database view I need to build a report based
I have a small problem with UINavigationController animation between two view. My application build
I have a view which I built in Interface builder with a tableview and
I have an application, built using MVC, that produces a view which delivers summary

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.