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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:55:36+00:00 2026-06-09T14:55:36+00:00

I tried to change the following code from an if statement into a switch

  • 0

I tried to change the following code from an if statement into a switch statement but I get an error saying that I need an integer and not an id object.

here’s my switch:

-(void) nearestIndexAfterRotationEnded:(int)index {
NSLog(@"Selected item is: %@", [colorNames objectAtIndex:index]);
statusLabel.text = [NSString stringWithFormat:@"Selected item is: %@", [colorNames objectAtIndex:index]];

switch ([colorNames objectAtIndex:])) {
    case 1:
        [redButton setImage:[UIImage imageNamed:@"Btn1_1.png"] forState:UIControlStateNormal];

        break;

    case 2:
        [redButton setImage:[UIImage imageNamed:@"Btn1_2.png"] forState:UIControlStateNormal];

        break;

    default:
        break;
}

and here’s my if conditional statement:

-(void) nearestIndexAfterRotationEnded:(int)index {
NSLog(@"Selected item is: %@", [colorNames objectAtIndex:index]);
statusLabel.text = [NSString stringWithFormat:@"Selected item is: %@", [colorNames objectAtIndex:index]];


if ([colorNames objectAtIndex:0]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_1.png"] forState:UIControlStateNormal];

}

if ([colorNames objectAtIndex:1]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_2.png"] forState:UIControlStateNormal];

}

if ([colorNames objectAtIndex:2]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_3.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:3]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_4.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:4]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_5.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:5]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_6.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:6]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_7.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:7]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_8.png"] forState:UIControlStateNormal];
}

if ([colorNames objectAtIndex:8]) {
    [redButton setImage:[UIImage imageNamed:@"Btn1_9.png"] forState:UIControlStateNormal];
}

}

thanks for any help

  • 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-09T14:55:38+00:00Added an answer on June 9, 2026 at 2:55 pm
    Change it the code 
     switch ([colorNames objectAtIndex:]))
    to 
    switch (index)  This will be helpful for you.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which works perfectly but I need an onblur statement
Anything I have tried didn't work. Currenly I have following code to change asp.net
I recently ran into an error when I tried to change the column name
I have this code with the switch statement which I got from this post
I have the following code that returns rows from a database when a form
I have the following code snippet I'm trying to get the text from: <span
I have the following code which should change the value of an h2 from
I'd like to change my following code from synchronous to async AJAX for performance
I've got the following code which I've put together, and I need to change
I've tried to change filenames using following script: find dir/ -type f -exec mv

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.