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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:53:50+00:00 2026-05-28T03:53:50+00:00

I have a table view with 3 items, one of which I have behind

  • 0

I have a table view with 3 items, one of which I have behind a button. When the button is selected, I want to hide that button, revealing the item behind it. I am displaying the table row using a table view cell. When I select the one button to hide, scrolling through the table hides more buttons. The hiding of the button seems to hide a button based on some location within the viewable rows of the current view. I’m trying to hide the button on a specific row.

I can write to the NSLog whenever I hit the code to hide a button and I will only get there once, but as I scroll through the table, the hidden attribute for the button applies to other rows that come into view. If I select the button on row 53 I want only the button in row 53 hidden, not buttons on other rows in the 120 row table.

Has anyone ever done what I am trying to do? Any help I can get to figure out what is happening would be appreciated. Thanks.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ElementCellIdentifier = @"ElementCellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ElementCellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ElementRowCell"
                                                 owner:self options:nil];
        if ([nib count] > 0) {
            cell = self.tvCell;
        } else {
            NSLog(@"failed to load ElementRowCell nib file!");
        }
    }

    NSUInteger row = [indexPath row];

    UILabel *atomic_number = (UILabel *)[cell.contentView viewWithTag:1];                               
    atomic_number.text = [NSString stringWithFormat:@"%d",elements_table[row].atomic_number];

    UILabel *element_name = (UILabel *)[cell.contentView viewWithTag:2];
    element_name.text = [NSString stringWithCString:elements_table[row].element_name];

    UILabel *element_symbol = (UILabel *)[cell.contentView viewWithTag:3];
    element_symbol.text = [NSString stringWithCString:elements_table[row].element_symbol];

    return cell;
}

- (IBAction)buttonPressed:(id)sender {

NSLog(@"Getting to buttonPressed from row button");
UIButton *pressedButton = (UIButton *)sender;
NSIndexPath *indexPath = [self.mainTableView indexPathForCell:     (UITableViewCell *)[sender superview]];
pressedButton.hidden = TRUE;

}

  • 1 1 Answer
  • 1 View
  • 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-28T03:53:50+00:00Added an answer on May 28, 2026 at 3:53 am

    Sorry.
    Basically what’s happening is you are hiding the instance of the button in that specific table view cell. The problem is when it gets dequeue’d for another row nothing is restoring it’s state. And if you were to just restore it’s state to visible then the rows you clicked would be forgotten. You will need to save the rows that have been clicked already to be able to properly restore state in tableView:cellForRowAtIndexPath:.

    How I would handle this is declare an NSMutableSet *selectedIndexPaths;. And use this to store the rows I have selected. Then when the button is clicked add that indexPath to the set like so.

    - (IBAction)buttonPressed:(UIButton *)button{
        if (![button isKindOfClass:[UIButton class]]) return;
        UIView *finder = button.superview;
        while ((![finder isKindOfClass:[UITableViewCell class]]) && finder != nil) {
            finder = finder.superview;
        }
        if (finder == nil) return;
        UITableViewCell *myCell = (UITableViewCell *)finder;
        NSIndexPath *indexPath = [self.mainTableView indexPathForCell:myCell];
        [selectedIndexPaths addObject:indexPath];
        button.hidden = TRUE;
        NSLog(@"IndexPathRow %d",indexPath.row);
    }
    

    Now to properly restore state when scrolling in tableView:cellForRowAtIndexPath: use an if statement to set the button’s hidden property, like so:

    buttonPropertyName.hidden = ([selectedIndexPaths containsObject:indexPath]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a view for each table (letters, filings, notes) which each
I have a table view with a lot of items when i click on
I have created a TableView(Grouped Table View). And I can list the items in
Imagine you have a normal table view where each row is an item on
I have a Table View Controller with cells. I want to update the text
I have a table view that I am customizing and I am adding a
I have a table view that is managed by an NSFetchedResultsController. I am having
I have a table view controller which doesn't let me manually scroll to the
I'm making a shopping cart. In one tab, I have a table view controller
I have a view which has it's own navigation bar and one tableview. I

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.