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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:32:15+00:00 2026-05-14T23:32:15+00:00

In the iPhone app I’m currently working on, I’d like two view controllers (I’ll

  • 0

In the iPhone app I’m currently working on, I’d like two view controllers (I’ll call them A and B) to have toolbars that are identical in appearance and function. The toolbar in question will look like this:

[(button) (flexible-space) (label)]

For posterity’s sake, the label is actually a UIBarButtonItem with a custom view.
My design requires that A always appear directly before B on the navigation stack, so B will never be loaded without A having been loaded. Given this layout, I started wondering,

“Is it worth it to re-use A’s toolbar items in B’s toolbar?”

As I see it, my options are:
1. Don’t worry about re-use, create the toolbar items twice
2. Create the toolbar items in A and pass them to B in a custom initializer
3. Use some more obscure method that I haven’t thought of to hold the toolbar constant when pushing a view controller

As far as I can see, option 1 may violate DRY, but guarantees that there won’t be any confusion on the off chance that (for example) the button may be required to perform two different (no matter how similar) functions for either view controller in future versions of the app. Were that to happen, options 2 or 3 would require the target-action of the button to change when B is loaded and unloaded. Even if the button were never required to perform different functions, I’m not sure what its proper target would be under option 2.

All in all, it’s not a huge problem, even if I have to go with option 1. I’m probably overthinking this anyway, trying to apply the dependency injection pattern where it’s not appropriate. I just want to know the best practice should this situation arise in a more extreme form, like if a long chain of view controllers need to use identical (in appearance and function) UI elements.

  • 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-14T23:32:15+00:00Added an answer on May 14, 2026 at 11:32 pm

    It really does depend on how things might change in the future. Assuming for the moment that (at most) the text in the label and the targets for the actions might change, I would lean in the direction of reuse. What I actually did in this case was create a common base class for my view controllers that had a utility method for creating the toolbar items. They can either be created programmatically or pulled from a nib. Either way, this is pretty flexible for future reuse (just subclass another controller) or divergence (remove the superclass relationship and implement your situation-specific toolbar on the controller that has changed).

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

Sidebar

Related Questions

Our iPhone app code currently uses NSURLConnection sendSynchronousRequest and that works fine except we
The iPhone app that I am working on requires GET calls to a 3rd
My iPhone app initiates a phone call with: NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@tel://%@,
The iPhone app I'm working on uses html help files and special characters such
My iPhone app generates some very nice-looking plist files. I can look at them
The iPhone app I am developing has a strange quirk where it runs ok
My iPhone app was running fine. I added a component to my xib file
my iphone app crashes unexpectedly and looking at the crash log I can't tell
My iphone app writes key-value pairs to a dictionary in a plist file. I'm
My iPhone app rotates fine in the simulator but when I deploy it on

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.