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

  • Home
  • SEARCH
  • 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 6933619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:51:21+00:00 2026-05-27T11:51:21+00:00

I have a UITableView in which each UITableViewCell having a UIView on them and

  • 0

I have a UITableView in which each UITableViewCell having a UIView on them and and above UIView i have two UIButton and two UILabel. My problem is this when i am reloading the tableview then the new data is rewritten on the old data that makeks content blurred and unclear and in method cellForRowAtIndexPath i used this code of removing label then it is also not working properly…….

NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
    for (UILabel *subview in subviews) {
        [subview removeFromSuperview];
    }
    [subviews release];

This code is showing a row at a time otherwise no one…

The code of cellForRowAtIndexPath is this….

- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *dict = [appDelegate.webDataList objectAtIndex:indexPath.row];

    tableView.backgroundColor = [UIColor colorWithRed:0.39 green:0.39 blue:0.39 alpha:0.39];

    if([appDelegate.dataArray count]>0){

        imgView.backgroundColor = [UIColor clearColor];
        imgView =[[UIView alloc ] initWithFrame:CGRectMake(0,0,320,45)];
        imgView.tag= indexPath.row+250;
        [cell.contentView addSubview:imgView];

        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(291, 5, 19, 21);
        img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"swap_re" ofType:@"png"]];
        [button setBackgroundImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(swapButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        button.tag= indexPath.row+250;
        [imgView addSubview:button];

        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(-25, 5, 19, 21);
        img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"swap_re" ofType:@"png"]];
        [button setBackgroundImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(swapButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        button.tag= indexPath.row+250;
        [imgView addSubview:button];

        button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(5, 7, 19, 21);
        button.tag = indexPath.row+250;
        img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"delete" ofType:@"png"]];
        [button setBackgroundImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];    
        [imgView addSubview:button];

        NSArray *arr = [[appDelegate.dataArray objectAtIndex:indexPath.row] componentsSeparatedByString:@"/"];


        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(34,9,140,20)];
        label.text = [arr objectAtIndex:1];
        label.tag = indexPath.row+250;
        [label setFont:[UIFont fontWithName:@"Georgia" size:14]];
        [label setNumberOfLines:0];
        label.textAlignment = UITextAlignmentLeft;
        label.textColor = [UIColor whiteColor];
        label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        label.backgroundColor = [UIColor clearColor];
        [imgView addSubview:label];
        [label release];

        NSDictionary *dict1 =[appDelegate.webDataList objectAtIndex:indexPath.row];


        label = [[UILabel alloc] initWithFrame:CGRectMake(181, 7, 75, 20)];
        label.tag = indexPath.row+250;
        label.text = [dict1 objectForKey:@"time"];
        [label setFont:[UIFont fontWithName:@"Georgia" size:16.0]];
        label.textAlignment = UITextAlignmentLeft;
        [label setBackgroundColor:[UIColor clearColor]];
        label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [label setTextColor:[UIColor whiteColor]];
        [imgView addSubview:label];
        [label release];
    }
    return cell;
}

and in my code i am not able to use the method reuseTableViewCellWithIdentifier: because i want each label and button tag should be same because i have to fetch them else where.

  • 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-27T11:51:21+00:00Added an answer on May 27, 2026 at 11:51 am

    That happens because you are doing it wrong. You don’t even need to reload the table. Just scroll around and you will notice it.
    You create new labels and buttons each time a cell is displayed. And those UI elements are of course never removed.

    Add the UI element when you create a new cell and give them a tag.
    If the cell was successful dequeued get the element by that tag and set its values.

    Like this:

    if (cell == nil) {
        // if no cell could be dequeued create a new one
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    
        // add label to the new cell
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(34,9,140,20)];
        label.tag = 250;  // <---- save tag
        [label setFont:[UIFont fontWithName:@"Georgia" size:14]];
        [label setNumberOfLines:0];
        label.textAlignment = UITextAlignmentLeft;
        label.textColor = [UIColor whiteColor];
        label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        label.backgroundColor = [UIColor clearColor];
        //[imgView addSubview:label]; // I ignore this because I don't want to write 200 lines of code here. This is just an example so please adopt the code yourself
        [cell.contentView addSubView:label];
        [label release];
    }
    
    // whatever happened you have a cell with all the labels added here
    
    UILabel *label = (UILabel *)[cell.contentView viewWithTag:250]      // <---- get label with tag
    label.text = [arr objectAtIndex:1];
    

    and you don’t need if([appDelegate.dataArray count]>0). If all your other tableview datasource methods are correct tableView:cellForRowAtIndexPath: isn’t called if your data source is empty.


    Edit: Just saw that one:

    and in my code i am not able to use the method reuseTableViewCellWithIdentifier: because i want each label and button tag should be same because i have to fetch them else where.

    Actually you can. Everybody can and should use reuseTableViewCellWithIdentifier:.
    What are your exact problems with that?
    If you need to get the indexPath (or in your case only the row) in the button action method use the code from my answer to another question

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

Sidebar

Related Questions

I have a UITableView with 5 UITableViewCells . Each cell contains a UIButton which
I have a UITableView. I place an UIImageView on each row UITableViewCell. I used
I have a UITableView with two sections, which are both empty when my application
I have a UITableView with a few UITableViewCell s. Each cell contains a UITextfield
I have a UITableView with each cell containing the following 1) A UILabel (listing
I've made a UITableView with cells which have different height. On each cell, I've
I have one iphone application in which i am adding uitableview inside uitableviewcell.in that
I have a UITableView with a set of UITableViewCell s in it - each
I've got a little problem in my UITableViewCell. Each Custom Cell have an UISwitch
I have a UITableView which is populated by an array, I have a button

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.