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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:44:41+00:00 2026-05-13T13:44:41+00:00

What is the best way when setting up a UI for the iPhone to

  • 0

What is the best way when setting up a UI for the iPhone to differentiate between multiple items of the same type (i.e. 2 sliders) currently I am assigning the controls unique “tags” and then querying them in Xcode. Is this the way to go or am I missing something else?

-(IBAction)switchChanged:(UISwitch*)senderSwitch {
    if([senderSwitch tag] == 1) {
        NSLog(@"SwitchChanged: Engines");
    }
    ...

gary

  • 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-13T13:44:41+00:00Added an answer on May 13, 2026 at 1:44 pm

    Hey Gary! I usually choose similar approach, though I prefer using integer constants instead of ‘raw’ numbers. Here’s an example:

    const int VIEW_TAG_A_SWITCH = 1;
    const int VIEW_TAG_OTHER_SWITCH = 2;
    
    - (IBAction)switchChanged:(UISwitch*)senderSwitch {
        switch (senderSwitch.tag) {
            case VIEW_TAG_A_SWITCH:
                // do something
                break;
            case VIEW_TAG_OTHER_SWITCH:
                // do something else
                break;
        }
    }
    

    This makes code more informational and help you to deal with situations when you need to change the UIView tag value for some reason (this way you only change it once in your nib and once in your code).

    It’s also very handy to use enums when you need to work with a group of controls. Here’s a dummy single selection group of buttons example (something similar to what <input type="option" />):

    enum GenderOptionButtons {
        kMaleGenderOptionButton = 10,
        kFemaleGenderOptionButton,
        kUndefinedGenderOptionButton,
        NUM_GENDER_OPTION_BUTTONS
    }
    
    - (IBAction)buttonDidTouchUpInside:(UIButton *)senderButton {
        for (int i = kMaleGenderOptionButton; i < NUM_GENDER_OPTION_BUTTONS; i ++) {
            [(UIButton *)[self.view viewWithTag:i] setSelected:NO];
        }
    
        senderButton.selected = YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the best way to store per-Build configuration information for an iPhone
I'm stuck thinking about the best way to go about setting a line segment's
I am wondering the best way about setting up asp.net membership in sql server
Wondering if there’s a plugin or best way of setting up an ActiveRecord class
What is the best way to use multiple EVAL fields in a GridView ItemTemplate?
I'm setting up links and not sure which is the best way to link
What is the best way to test a live tile update? I am setting
What is the easiest and best way to trigger change event when setting the
What do people think is the best way of setting up a Java, maven-2
What is the best way to store settings for certain objects in my database?

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.