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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:38:17+00:00 2026-06-12T14:38:17+00:00

I have an iPhone app problem that’s been bugging me for a few days

  • 0

I have an iPhone app problem that’s been bugging me for a few days and it really doesn’t seem like it should be this difficult so I’m sure I’m missing something obvious. I have researched plenty of forum discussions on “similar” topics but nothing that actually addresses this issue, specifically.

To be clear, if there is some piece of documentation or some other source that I should research, please point me in the right direction.

Here goes…

I have a list of items that I display to the user within a table (uitableview). The cell (uitableviewcell) for each item is custom and contains two image buttons(uibuttons: green and red). As expected, for each item in the the table, the user can click any of the buttons. Based on a parameter called monitoringRequestType for a button, the button calls a separate process to update the server. If the state is “Approved”,the image changes to ‘alreadyapproved’ and ‘reject’ respectively. So when I click on the red button, server updates the state to “Rejected” and image then changes to ‘approve’ and ‘alreadyrejected’.
Simple, right?

So, here is the issue:

On clicking the reject button, the ‘approve’ image comes on top of the ‘alreadyapproved’ image (so both images can be seen) while ‘alreadyrejected’ image works fine.For brevity, I am only including the relevant code here (hopefully formatted properly):

CellForRow:
if(indexPath.section==0){
    NSDictionary *dict=[saveJson objectAtIndex:indexPath.row];
    NSString* sMonitoringType = [dict valueForKey:@"monitoringType"];
    UIButton *button1= [[UIButton alloc] initWithFrame:CGRectMake(230,10,40,40)];
    UIButton *button2= [[UIButton alloc] initWithFrame:CGRectMake(280,10,40,40)];
    if([sMonitoringType compare:@"Pending"] == NSOrderedSame){
        [button1 setImage:[UIImage imageNamed:@"approve"]     
                 forState:UIControlStateNormal];
        [button1 addTarget:self
                    action:@selector(greenButtonPressed:withEvent:) 
          forControlEvents:UIControlEventTouchUpInside];
         button1.tag= indexPath.row;   
        [button2 setImage:[UIImage imageNamed:@"reject"]
                 forState:UIControlStateNormal];
        [button2 addTarget:self
                    action:@selector(redButtonPressed:withEvent:) 
          forControlEvents:UIControlEventTouchUpInside];
         button2.tag= indexPath.row;             
    } else if([sMonitoringType compare:@"Approved"] == NSOrderedSame){
        [button1 setImage:[UIImage imageNamed:@"alreadyapproved"] 
                 forState:UIControlStateNormal];
        [button2 setImage:[UIImage imageNamed:@"reject"]
                 forState:UIControlStateNormal];
        [button2 addTarget:self
                    action:@selector(redButtonPressed:withEvent:) 
          forControlEvents:UIControlEventTouchUpInside];
         button2.tag= indexPath.row;
    } else if([sMonitoringType compare:@"Rejected"] == NSOrderedSame){
        [button1 setImage:[UIImage imageNamed:@"approve"] 
                 forState:UIControlStateNormal];
        [button2 setImage:[UIImage imageNamed:@"alreadyrejected"] 
                 forState:UIControlStateNormal];
        [button1 addTarget:self
                    action:@selector(greenButtonPressed:withEvent:) 
          forControlEvents:UIControlEventTouchUpInside];
         button1.tag= indexPath.row;
    }
    [cell addSubview:button1];
    [cell addSubview:button2];
    [button1 release];
    [button2 release];
}
return cell;
}
  • 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-12T14:38:18+00:00Added an answer on June 12, 2026 at 2:38 pm

    The UIButtons are being added to the cell’s subview whenever the cell reloads (you’re reusing cells, right?). You should reuse the older buttons already added to the cell’s subview instead of adding new ones and just to verify the issue, stop reusing the cells (memory inefficient, should not be done in production code!). To reuse the older buttons, set a unique tag for each button and get them back as [cell viewWithTag:uniqueTag]

    if(indexPath.section==0){
      NSDictionary *dict=[saveJson objectAtIndex:indexPath.row];
      NSString* sMonitoringType = [dict valueForKey:@"monitoringType"];
      UIButton *button1= [cell viewWithTag:900];
      UIButton *button2= [cell viewWithTag:901];
      if(!button1){// button1 doesn't exist yet (first time)
        button1 = [[UIButton alloc] initWithFrame:CGRectMake(230,10,40,40)];
        [cell addSubview:button1];
      }
      if(!button2){// button2 doesn't exist yet (first time)
        button1 = [[UIButton alloc] initWithFrame:CGRectMake(280,10,40,40)];
        [cell addSubview:button2];
      }
      ......
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app problem that's been bugging me for a few days
Very strange problem with my iPhone App. We have an App that has been
I have an iPhone app that allows users to record videos and I'd like
I have an iPhone app that's been in development for about 2 weeks. We
I have an iPhone app, and I would like it so that when a
I have a iPhone app that I'm working on and it works alot like
I have an iPhone app in development that requires three slides (views). The problem
I have an iPhone app that I've built for the app store. Before I
I have an iPhone app that I am writing and it has 2 targets
I have an iphone app i want that befor moving to next screen it

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.