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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:13:49+00:00 2026-06-12T18:13:49+00:00

I am developing an iOS app screen, where i’m having around 25 buttons, clicking

  • 0

I am developing an iOS app screen, where i’m having around 25 buttons, clicking on each button will launch a separate view controller. Basically, i have implemented like having one ‘IBAction’ and provide ‘tag id’ for each button. Under this button action, based on button tag id, i am launching each view controller. Problem here is, i’m programming via switch case for identifying this button id’s, but i want to avoid using this switch case and looking to provide more efficient programming here. How it is possible to remove ‘switch case’ but provide better way of programming for this situation.

  • 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-12T18:13:50+00:00Added an answer on June 12, 2026 at 6:13 pm

    Here a switch statement seems to be the cleanest and most efficient way to do things, you could have a big if-elseif but if you’re giving the cold shoulder to switch then that’s even less of an option for you I guess.

    If you really want to avoid a switch then what you could do is tag your buttons from 0 to 24, and have an NSArray containing an array of the names of your view controller’s class, then use NSClassFromString to get the class reference from which to instantiate an object of that class.

    Then you could do something like:

    - (id)init{
        self = [super init];
        if(self){
            self.classesArray = @[@"MyControllerOne", @"MyControllerTwo", @"MyControllerThree"];
        }
        return self;
    }
    
    [...]
    
    - (IBAction)tappedButton:(UIButton *)sender{
        NSString *viewControllerClassString = [self.classesArray objectAtIndex:sender.tag];
        id viewController = [[NSClassFromString(viewControllerClassString) alloc] init];
    
        // Present it modally? Push it onto the stack? 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a iOs 5 app ( View in App Store ) with native
I'm developing an iOS App and I want to make a table view, but
I am developing an iOS app using iOS 5. I am having trouble using
I'm having an issue developing a phonegap app for iOS. I just copied all
I'm developing an app for iOS. This is a game. In the game screen
I'm new in developing iOS app. So I've recently faced a problem with localization
I'm developing an iOS app using Core Plot headers. I have different UI for
I am developing an iOS app with a tab bar controller. In the first
I am developing an IOS app. I need a functionality that includes undo and
I'm developing an iOS app. Its working properly on simulator. I'm using phonegap and

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.