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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:44:27+00:00 2026-05-23T04:44:27+00:00

I have a table view and some buttons inside it. 4 buttons in one

  • 0

I have a table view and some buttons inside it. 4 buttons in one row then another 4 in second row and so one. I am using array for adding images to the buttons.

For the first time it is working properly but when delete all the items in the array and new objects to the array and then call reload table view, the new data is not reloaded.

What could be the reason?

I am posting a part of my code:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // if (cell == nil) {
    // cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    // }
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    if(indexPath.row == 0)
    {
        button1=[[UIButton alloc] initWithFrame:CGRectMake(15,5,100,87)];
        [button1 setImage:[array objectAtindex:0]
        [button1 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:self.button1];

        button2=[[UIButton alloc] initWithFrame:CGRectMake(135,5,100,87)];
        [button2 setImage:[array objectAtindex:1] forState:UIControlStateNormal];
        [button2 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button2];
    }
    else if(indexPath.row == 1)
    {
        button3=[[UIButton alloc] initWithFrame:CGRectMake(15,5,100,87)];
        [button3 setImage:[array objectAtindex:2] forState:UIControlStateNormal];
        [button3 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button3];


        button4=[[UIButton alloc] initWithFrame:CGRectMake(135,5,100,87)];
        [button4 setImage:[array objectAtindex:3] forState:UIControlStateNormal];
        [button4 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button4];
    }
    else
    {
        // Do something here
    }
    return cell;
}

my click button:

-(IBAction)clickToDisplayImage { 
    [text resignFirstResponder]; 
    if([imageArray count] >0) 
    {
       [imageArray removeAllObjects]; 
    }  
    int totalImages = [text.text intValue]; 

    for( int i=0;i<totalImages;i++) 
    { 
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i]]]; 
    } 
    [tableView reloadData]; 

}

  • 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-23T04:44:28+00:00Added an answer on May 23, 2026 at 4:44 am

    When you call reloadData on your UITableView, your cellForRowAtIndexPath message will be called to populate the row. Because you have already created the cells from the first pass, when you call dequeueReusableCellWithIdentifier you will get back your originally created cells associated with the @”Cell” identifier.

    You can confirm this by setting a breakpoint and checking that the second time through you will get your cell from dequeueReusableCellWithIdentifier (rather than a newly created cell). You will then be adding new subviews to that original cell (so four button subviews for the cell, then six, eight etc…).

    What you should be doing is only adding the button subviews when you first create the cell (so move the button create stuff into the if (cell == nil) block) and you should be using a cell identifier based on the table row. Something like:

    - (UIButton*) getButtonLeft:(BOOL)left atIndex:(int)index
    {
        UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake((left ? 15 : 135),5,100,87)];
        [button setImage:[array objectAtindex:index] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
        return button;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // both rows are different so we should use a different re-use id.
        NSString * CellIdentifier= [NSString stringWithFormat:@"Cell%d", indexPath.row];
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
            switch (indexPath.row)
            { 
                case 0:
                    button1 = [self getButtonLeft:YES atIndex:indexPath.row];
                    [cell.contentView addSubview:button1];
                    break;
                case 1:
                    button2 = [self getButtonLeft:NO atIndex:indexPath.row];
                    [cell.contentView addSubview:button2];
                    break;
                case 2:
                    button3 = [self getButtonLeft:YES atIndex:indexPath.row];
                    [cell.contentView addSubview:button3];
                    break;
                case 3:
                    button4 = [self getButtonLeft:NO atIndex:indexPath.row];
                    [cell.contentView addSubview:button4];
                    break;
                default:
                    // other cells?
                    break;
            }
        }
    
        // if you need to modify the cell you have dequeued/created this is where you would do that
    
        return cell;
    }
    

    N.B. I haven’t run this code through a compiler, so ware syntax errors 😉

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

Sidebar

Related Questions

I'm having three buttons on table view cell and have to show some text
When I have a table view with some sections which have their own headers
I have a table view that I am customizing and I am adding a
In my iPhone application I have a table view. When user taps any row,
I have some uiButtons in my table view and i want to load them
I have a view based project with a set of buttons. When one of
I have a grouped table view that contains 3 sections and each row per
I have a table view with 3 items, one of which I have behind
I have a table view that I want to delete some of the cells
I have a Table View Controller with cells. I want to update the text

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.