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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:25+00:00 2026-05-23T07:21:25+00:00

I am having difficulty in changing the image of my UIButton which is contained

  • 0

I am having difficulty in changing the image of my UIButton which is contained within a table view cell. My code as follows:

 // In tableview for cell at rowIndex method
 self.iconBtn = [[UIButton alloc]initWithFrame:CGRectMake(670,10,80, 80)];
            self.iconBtn.tag = kIconValueTag;

 [cell.contentView addSubview:self.iconBtn];

 //Add icon to cell
 UIImage *btnImage = [UIImage imageNamed:@"blank_star.png"];

 [self.iconBtn setImage:btnImage forState:UIControlStateNormal];

 // I am calling method changeIconState after user clicks on icon.
 [self.iconBtn addTarget:self action:@selector(changeIconState) forControlEvents:UIControlEventTouchUpInside];

After the button is pressed, a method outside the table view method is called:

-(void)changeIconState
{
    if (self.iconSelectState == kIconNotSelected) 
    {
        self.iconSelectState = kIconSelected;
    }
    else
    {
        self.iconSelectState = kIconNotSelected;
    }
    [self changeIcon];

}
-(void)changeIcon
{
    if (self.iconSelectState == kIconSelected) 
    {
        UIImage *btnImageHighlighted = [UIImage imageNamed:@"star.png"];
        [self.iconBtn setImage:btnImageHighlighted forState:UIControlStateNormal];
    }
    else
    {
        UIImage *btnImageNormal = [UIImage imageNamed:@"blank_star.png"];
        [self.iconBtn setImage:btnImageNormal forState:UIControlStateNormal];
    }

}

After I run the program, the icon did not change from blank to star as I wanted. It just remained as a blank star. Is there anything I am missing out here?

  • 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-23T07:21:26+00:00Added an answer on May 23, 2026 at 7:21 am

    Why are you managing the image/button state yourself? Why not load the two images for the defined states and let the OS handle it?

     //Add icon to cell
     UIImage *btnImage = [UIImage imageNamed:@"blank_star.png"];
     UIImage *btnImageHighlighted = [UIImage imageNamed:@"star.png"];
    
     [self.iconBtn setImage:btnImage forState:UIControlStateNormal];
     [self.iconBtn setImage:btnImageHighlighted forState:(UIControlStateHighlighted && UIControlStateSelected)];
    

    If you need to manage your property (iconSelectedState) you can without worrying about the image. Alternatively, you can query the buttons state property to determine which state it is in.

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

Sidebar

Related Questions

Hello I am having difficulty changing the visual view of the fragment activity. I
I'm having difficulty thinking through the design tradeoffs of changing the root view controller
This concerns iPhoneOS-sdk-3.2 I am having difficulty changing the border color of a grouped
I'm having difficulty with a query which displays records according to their fill rate.
I am having difficulty updating a table via PHP. Using MySQL prompt or a
I'm having difficulty converting some NSOperation code to ARC. My operation object uses a
I'm having difficulty changing the calue of a dropdown menu using jquery. <div class=input-box>
I've been playing around with RB tree implementation in Haskell but having difficulty changing
Hi I am having difficulty changing some attributes in jquery mobile dynamically for some
I am having some difficulty changing a hex to an int/char (char preferably). Via

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.