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

  • Home
  • SEARCH
  • 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

My iPhone app has a UIWebView that loads a page containing javascript that sets
I am building an iPhone app. Currently when I close the app and relaunch
My iPhone App is socket based and receives a continuous, non-delimited stream of XML
My iPhone app creates PDF files (in Arial font). The plain iPhone 3.1.x version
The iphone app I am creating has an array of commonly used settings. These
my iPhone app uses OpenGL ES in full screen mode (the status bar is
My iPhone app uses a small database to store its settings and saved files.
My iPhone app is using the MFMailComposeViewController class to send an in-app email with
An iPhone app which I am creating generates reports from a Core Data database
Fairly new to iPhone app development, so this might be really obvious (if so,

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.