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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:51:15+00:00 2026-05-14T08:51:15+00:00

This should be easy but its got me stumped. I’ve got a button on

  • 0

This should be easy but its got me stumped. I’ve got a button on each row of a table cell. The button is to delete the file associated with that row. I have an image that indicates if the file is present on the iPhone or not present.

When the user presses the button, the target action method (showDeleteSheet) then calls a UIActionSheet with a variable to give it the indexPath of the row pressed. Then the user presses delete on the action sheet and the action sheet’s clickedButtonAtIndex method deletes the file.

Now, I need to update the button’s background image property to change the image in the appropriate table cell to the not downloaded image. This can be done in either the button’s target action method or the action sheet’s clickedButtonAtIndex method.

Here is some code:

In the table’s cellForRowAtIndexPath method I create the button:

UIButton *deleteButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
    [deleteButton addTarget:self action:@selector(showDeleteSheet:) forControlEvents:UIControlEventTouchDown];
    deleteButton.frame = CGRectMake(246, 26, 30, 30);
    if (![AppData isDownloaded:[dets objectForKey:@"fileName"]]) {
        [deleteButton setBackgroundImage:notdownloadedImage forState:UIControlStateNormal];
    } else {
        [deleteButton setBackgroundImage:notdownloadedImage forState:UIControlStateNormal];
    }

In the button’s target method:

-(void)showDeleteSheet:(id)sender {
    //get the cell row that the button is in
    NSIndexPath *indexPath = [table indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
    NSInteger currentSection = indexPath.section;
    NSInteger currentIndexRow = indexPath.row;

    NSLog(@"section = %i row = %i", currentSection, currentIndexRow);

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [table reloadData];

    //if deleteButton is declared in .h then the other instances of deleteButton show 'local declaration hides instance variable'
    [deleteButton setBackgroundImage:[UIImage imageNamed:@"not-downloaded.png"] forState:UIControlStateNormal];


    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Delete this file?" 
                                             delegate:self 
                                    cancelButtonTitle:@"Cancel" 
                               destructiveButtonTitle:@"Delete" 
                                    otherButtonTitles:nil];                         
    actionSheet.tag = currentIndexRow;
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];
    [actionSheet release];

}

Perhaps the issue is that the call to [deleteButton setBackgroundImage…]; doesn’t know which cell’s button should be updated. If so I don’t know how to tell it which.

Because I test if the file is downloaded when the button is made and the background image is set, when I scroll down so the cell in question is de-queued then scroll back up it show’s the correct image.

I’ve tried to force the table to reload but [table reloadData]; is doing nothing. I’ve tried reloadRowsAtIndexPaths and still no good.

Any one care to educate me on how this is done?

  • 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-14T08:51:16+00:00Added an answer on May 14, 2026 at 8:51 am

    You could just store (id)sender from the

    -(void)showDeleteSheet:(id)sender
    

    method in an instance variable.

    self.curButton = sender;
    

    then call

    [curButton setBackgroundImage:image];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 398k
  • Answers 398k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could simply add the the MOUSE_MOVE event listener on… May 15, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer If you use Zend Frame Version 1.8 (+) put this… May 15, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer If you were allowed to use substr() it'd be so… May 15, 2026 at 3:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.