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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:04:52+00:00 2026-06-04T22:04:52+00:00

Trying to clean up some code and having issues doing so. I have a

  • 0

Trying to clean up some code and having issues doing so. I have a 1-5 ranking that appears in a uitableviewcell. The cell has 5 imageviews that point to a star image. There is a starYellow.png and starGrey.png. If the ranking is 3/5, the cell should set star1, star2, star3 to starYellow.png and star4, star5 to starGrey.png.

I am having issues referencing the property star%i where i is the iteration of the loop 1-5. I can’t work out how to do something like [cell setValue:starYellow forKey:[NSString stringWithFormat:@”star%i.image”, i]];

Here is the code I want to optimize..

if (book.ratingOnline) {
[cell.ratingView.layer setOpacity:1.0f];
    for (int i = 1; i <= 5; i++) {            
        if (i == 1) {
            if (book.ratingOnline >= i) { [cell.star1 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
            else { [cell.star1 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
        }
        else if (i == 2) {
            if (book.ratingOnline >= i) { [cell.star2 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
            else { [cell.star2 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
        }
        else if (i == 3) {
            if (book.ratingOnline >= i) { [cell.star3 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
            else { [cell.star3 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
        }
        else if (i == 4) {
            if (book.ratingOnline >= i) { [cell.star4 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
            else { [cell.star4 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
        }
        else if (i == 5) {
            if (book.ratingOnline >= i) { [cell.star5 setImage:[UIImage imageNamed:@"starYellow.png"]]; }
            else { [cell.star5 setImage:[UIImage imageNamed:@"starGrey.png"]]; }
        }
    }
}

Thanks.

  • 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-04T22:04:54+00:00Added an answer on June 4, 2026 at 10:04 pm

    Add all the stars in an NSArray,

    in Cell.h

    NSArray *stars;
    

    Now to reference any start you could do

    for (int i = 1; i <= 5; i++) {            
         UIImageView *star = [cell.stars objectAtIndex:i];
         //set the image to the star
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to clean up some code. I have a button that has the following
I am trying to clean up some data that has been incorrectly entered. The
I'm trying to clean up some old code that I wrote to comply with
I'm trying to clean up some warnings in some old Java code (in Eclipse),
I'm trying to get started with FMOD but I'm having some issues compiling the
I'm having 2 issues with a JQuery dialog widget that I'm trying to solve.
I'm writing some code in python and I'm having trouble when trying to retrieve
I'm trying to move some code into some class files to clean up my
I am trying to clean up some of the JavaScript throughout my views and
We just moved over to Git from SVN. In trying to clean up some

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.