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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:13:09+00:00 2026-06-16T17:13:09+00:00

My recent frustration is a UIButton subview in each UITableViewCell of my UITableView which

  • 0

My recent frustration is a UIButton subview in each UITableViewCell of my UITableView which I want to setHidden: according to a specific clause for each indexPath. My code is pretty much the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        [self initCell:cell forIndexPath:indexPath];
    }
    [self updateCell:cell forIndexPath:indexPath];
    return cell;
}

and the init and update methods are the following:

- (void)initCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
    ...

    UIButton *btnMy = [UIButton buttonWithType:UIButtonTypeCustom];
    btnMy.tag = kButtonMyTag;
    [btnMy setFrame:CGRectMake(170, 45, 100, 30)];
    [btnMy setBackgroundImage:[UIImage imageNamed:@"btn_image"] forState:UIControlStateNormal];
    btnMy.adjustsImageWhenHighlighted = YES;
    [btnMy setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnMy.titleLabel.font = [UIFont fontWithName:@"MyFont" size:14];
    [btnMy addTarget:self action:@selector(btnMyPressed:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:btnMy];

    UIImageView *imgViewAccessory = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table_accessory"]];
    cell.accessoryView = imgViewAccessory;
    [imgViewAccessory release];
}

- (void)updateCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
    UIButton *btnMy = (UIButton *)[cell viewWithTag:kButtonMyTag];

    MyObject *object = (MyObject *)[self.dataSource objectAtIndex:indexPath.row];

    if(object.meetsCondition) 
    {
        btnMy.hidden = NO;
    }
    else 
    {
        btnMy.hidden = YES;
    }
    ...
}

The frustrating result is that when scrolling the button shows and hides randomly and not as expected according the if clause in the updateCell method.
Any help would be much appreciated. Thanks in advance!

  • 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-16T17:13:10+00:00Added an answer on June 16, 2026 at 5:13 pm

    You should make custom cell and depending upon the condition show and hide the button

    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSArray *nib;
        static NSString *cellIdentifier= @"cell";
    
        UITableViewCell *theCell = [self.tblView dequeueReusableCellWithIdentifier:cellIdentifier];
    
        if([theCell.contentView subviews]){
            for(UIView *view in [theCell.contentView subviews]){
                [view removeFromSuperview];
            }
        }
    
        if(theCell== nil)
        {
            nib  = [[NSBundle mainBundle] loadNibNamed:@"Your custom cell name" owner:self options:nil]; 
            theCell = [nib objectAtIndex:0];
            theCell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    
        UIButton *btn=(UIButton*)[theCell.contentView viewWithTag:101];
    if(yourcondition)
    //hide button
    else
    //show button
    }
    

    This will do

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

Sidebar

Related Questions

A recent homework assignment I have received asks us to take expressions which could
My recent app is like a forum, i use listview to show each thread.
A recent debate with a co-worker about different approaches to design and code the
In a recent question, Import a VB6 structure into C# , the code contained
In a recent programming interview, I was asked an SQL question to which I
A recent build of GCC 4.8 gives the following code, when in a header
Very recent i have to complete a project which have a small portion of
A recent question here made use of the default keyword in non-generic code that
Recent versions of Emacs support lexical binding for variables in elisp code. Is it
In recent versions, OpenCV allows easy creation of keypoint detectors, descriptors or matchers using

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.