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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:59+00:00 2026-06-08T02:55:59+00:00

Let’s say I have a two subclasses of UIViewController called MasterViewController and DetailViewController .

  • 0

Let’s say I have a two subclasses of UIViewController called MasterViewController and DetailViewController.

DetailViewController has a property of type NSNumber called level and a UILabel called levelLabel.

MasterViewController has a segue to DetailViewController called ToDetail. MasterViewController‘s prepareForSegue is like so

    - (void)prepareForSegue:(UIStoryboardSegue)segue sender:(id)sender
    {
       if ([segue.identifier isEqualToString:@"ToDetail"]) {
         DetailViewController *detailVC = (DetailViewController *)segue.destinationViewController;
         detailVC.level = [NSNumber numberWithInt:10]; // never mind the literal...pretend there was some algorithm for it
       }
     }

So then, in DetailViewController we implement the setter for levelLabel like so:

     - (void)setLevelLabel:(UILabel *)levelLabel
     {
       if (levelLabel) {
         _levelLabel = levelLabel;
         _levelLabel.text = level.stringValue;
       }
     }

Is this good code design? Also, could you critique my code writing style? I pretty much wrote all this code on the fly so this is pretty much how I write code for the most part.

I thought of this question while showering because this is how I implement the setting of almost all the label texts that depend on a segue.

  • 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-08T02:56:00+00:00Added an answer on June 8, 2026 at 2:56 am

    What follows is my own way of thinking about such relationships. Italics applies to your question.

    You have the thing being controlled (the label) the controller (destination view controller) and the context it is being controlled within (the source view controller). This can also be expressed as model-view-controller, but I think thinking about a context can apply to much more specific and localised situations.

    You should generally try to keep information flow going in one direction, from the context downwards. Objects should not have to be aware of the context in which they exist, ie they shouldn’t have to ask for any information, they should be told everything they need to operate. So the source view controller should push the level to the destination view controller, the destination view controller should push this information to the label. This is what you already have, sort-of.

    To build upon the above, not only should information flow in one direction, but I also try to ensure the relationships are causal, ie pushing information from one object to another should cause it to subsequently be pushed to the next object. Your code is not doing this which is probably why you have a bad feeling about it.

    A more appropriate thing to do is set the text property of the label within the level setter, so that when you set or change the level, the label will update subsequently. The label may or may not be loaded so you will have to check whether it is using -isViewLoaded; -viewDidLoad is the appropriate place to set the text property upon first load.

    (When I say ‘push’ that’s just my way of thinking about setting properties or passing arguments because it implies directionality. It is really dependency injection. An example of pulling information would be delegates and data sources. But note here still the object isn’t aware of any context, delegates and data sources are clearly defined as protocols, not classes, and usually within the same header file, and are themselves pushed onto the object from a surrounding context. So yes the object is asking for information, but on its own terms and from a system it has no knowledge of.)

    Re coding style:

    That’s exactly how I write code but note Apple reserves the use of underscore prefixes

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

Sidebar

Related Questions

Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I have two objects, Master and Slave . Slave has a method
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following two lists of tuples myList = [(1, 7),
Let's say I have 2 windows in my application, and two classes responsible for
Let's say we have this code: <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input
Let's say I have following hierarchy of levels: level 1 stage 1 stage 2
Let's say I don't have photoshop, but I want to make pattern files (.pat)

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.