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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:38:23+00:00 2026-05-15T10:38:23+00:00

I added a subviews to uitableviewcells its working fine, but when I scroll up

  • 0

I added a subviews to uitableviewcells its working fine, but when I scroll up or down subviews are adding multiple times. I donno where I am wrong.

Here is my code:

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

 static NSString *CellIdentifier = @"MainPageCellView";
 MainPageTableCellView *cell = (MainPageTableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 if (cell == nil) {  
  [[NSBundle mainBundle] loadNibNamed:@"MainPageTableCellView" owner:self options:nil];  
  cell = mainPageTableCell;
 } 



 [cell setNameText:[namesArray objectAtIndex:indexPath.row]];
 [cell setPositionText:[positionArray objectAtIndex:indexPath.row]];
 [cell setCompanyNameText:[companyNameArray objectAtIndex:indexPath.row]];
 [cell setDistanceText:[distArray objectAtIndex:indexPath.row]];
 [cell setImageViewImage:[imagesArray objectAtIndex:indexPath.row]];


 UIImage *halo = [UIImage imageNamed:@"h1.png"]; 
 UIImageView *haloV = [[UIImageView alloc] initWithImage:halo];

 if(indexPath.row == 0)
 [cell addSubview: haloV];
 else if(indexPath.row ==2)
 [cell addSubview: haloV];
 else if(indexPath.row ==3)
 [cell addSubview: haloV];


 return cell;

}
  • 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-15T10:38:23+00:00Added an answer on May 15, 2026 at 10:38 am

    You are adding subviews to the cells whether or not they have just been created or they are being reused. When you scroll up and down, they get reused, and thus the subviews get added repeatedly.

    Move the calls to addSubview within the if (cell==nil) block and that should fix the problem.

     if (cell == nil) {  
       [[NSBundle mainBundle] loadNibNamed:@"MainPageTableCellView" owner:self options:nil];  
       cell = mainPageTableCell;
    
       UIImage *halo = [UIImage imageNamed:@"h1.png"]; 
       UIImageView *haloV = [[UIImageView alloc] initWithImage:halo];
    
       if(indexPath.row == 0)
         [cell addSubview: haloV];
       else if(indexPath.row ==2)
         [cell addSubview: haloV];
       else if(indexPath.row ==3)
         [cell addSubview: haloV];
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController, and I've added two subviews to its view. One subview
Here's the scenario : I have a UITableView, and a UITextView, added as subviews
I created a zoomable UIScrollView and added 100 subviews to it (tiled). The view
I am working on UITableView. I have added a table in my view programmatically
I know that if I have some images and subviews added in customized cell
Working in a ViewController that has a few views which were added to it
In my app, i'm using an UIScrollView . I am adding some subviews to
i have a scrollview which has images added as subviews. i need to be
I have a parent UIView with several subviews but these are not visible and
When I set a view's exclusiveTouch property to YES, will any added subviews be

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.