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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:00:59+00:00 2026-05-20T05:00:59+00:00

I have been developing one application in iPhone and I’m making custom cells for

  • 0

I have been developing one application in iPhone and I’m making custom cells for a table view.
Following is the code for cellForRowAtIndexPath.

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


static NSString *CellIdentifier = @"Cell";

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

// Configure the cell...

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];


    NSDictionary *CurrentCommentRow = [comments objectAtIndex:indexPath.row];
    NSString *Comment = [[CurrentCommentRow objectForKey:@"Comment"] objectForKey:@"text"];
    NSString *FirstName = [[CurrentCommentRow objectForKey:@"F_Name"] objectForKey:@"text"];
    NSString *LastName = [[CurrentCommentRow objectForKey:@"L_Name"] objectForKey:@"text"];
    NSString *Date = [[CurrentCommentRow objectForKey:@"date"] objectForKey:@"text"];
    NSString *Time = [[CurrentCommentRow objectForKey:@"Time"] objectForKey:@"text"];
    NSString *UserImagePath = [[CurrentCommentRow objectForKey:@"UserImage"] objectForKey:@"text"];
    NSString *TotalComments = (NSString*)[[CurrentCommentRow objectForKey:@"TotalComment"] objectForKey:@"text"];
    NSString *imageRelativePath = [UserImagePath substringFromIndex:[UserImagePath rangeOfString:@"/" options:NSBackwardsSearch].location];


    UIView *CommentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 297, 140)];

    NSString* imageURL = [NSString stringWithFormat:@"http://primehangout.com/Images/IPhone%@",imageRelativePath];
    NSURL* url = [NSURL URLWithString:imageURL];        
    HJManagedImageV *managedImage = [[HJManagedImageV alloc] initWithFrame:CGRectMake(10, 18, 56, 56)];
    managedImage.url = url;
    [self.objManager manage:managedImage];
    [CommentView addSubview:managedImage];

    UILabel *lblName = [[UILabel alloc] initWithFrame:CGRectMake(82, 18, 180, 11)];
    lblName.font = [UIFont boldSystemFontOfSize:12];
    lblName.textColor = [UIColor colorWithRed:(5.0/255.0) green:(102.0/255.0) blue:(202.0/255.0) alpha:255];
    lblName.text = [NSString stringWithFormat:@"%@:",FirstName];        
    [CommentView addSubview:lblName];
    [lblName release];

    UITextView *txtViewComment = [[UITextView alloc] initWithFrame:CGRectMake(73, 34, 180, 40)];
    txtViewComment.contentInset = UIEdgeInsetsMake(-10,0,0,0);
    [txtViewComment setEditable:FALSE];
    txtViewComment.font = [UIFont fontWithName:@"Arial" size:11];
    txtViewComment.text = Comment;
    txtViewComment.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    [CommentView addSubview:txtViewComment];
    [txtViewComment release];


    UILabel *lblDateTime = [[UILabel alloc] initWithFrame:CGRectMake(82, 79, 180, 20)];
    lblDateTime.font = [UIFont fontWithName:@"Arial" size:10];
    lblDateTime.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    lblDateTime.text = [NSString stringWithFormat:@"%@ %@",Date,Time];      
    [CommentView addSubview:lblDateTime];
    [lblDateTime release];

    UILabel *lblTotalComments = [[UILabel alloc] initWithFrame:CGRectMake(82, 95, 80, 20)];
    lblTotalComments.font = [UIFont fontWithName:@"Arial" size:11];
    lblTotalComments.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    lblTotalComments.text = [NSString stringWithFormat:@"%@ Comments",TotalComments];       
    [CommentView addSubview:lblTotalComments];
    [lblTotalComments release];



    if ([TotalComments integerValue]>0) 
    {
        UIButton *btnViewAll = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnViewAll setFrame:CGRectMake(140, 82, 70, 45)];
        [btnViewAll setImage:[UIImage imageNamed:@"view_all_button_bg.png"] forState:UIControlStateNormal];
        //[lblViewAll setTitle:@"view all" forState:UIControlStateNormal];
        [btnViewAll addTarget:self action:@selector(ViewAllBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [btnViewAll setTag:(150 + indexPath.row)];
        [CommentView addSubview:btnViewAll];                    
    }
    else {
        [lblTotalComments setFrame:CGRectMake(82, 95, 150, 20)];
    }


    UIButton *btnAddComment = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnAddComment setFrame:CGRectMake(200, 82, 70, 45)];
    [btnAddComment setImage:[UIImage imageNamed:@"add_comment.png"] forState:UIControlStateNormal];
    [btnAddComment addTarget:self action:@selector(ViewAllBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [btnAddComment setTag:(1050 + indexPath.row)];
    [CommentView addSubview:btnAddComment];

    [cell.contentView addSubview: CommentView];

return cell;

}

The code works well in iPhone simulator but the tableview stucks at scrolloing in a real iPhone.

As I know that reusing can solve this problem I have tried out following code too:

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


static NSString *CellIdentifier = @"Cell";
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];


  // Configure the cell...




    NSDictionary *CurrentCommentRow = [comments objectAtIndex:indexPath.row];
    NSString *Comment = [[CurrentCommentRow objectForKey:@"Comment"] objectForKey:@"text"];
    NSString *FirstName = [[CurrentCommentRow objectForKey:@"F_Name"] objectForKey:@"text"];
    NSString *LastName = [[CurrentCommentRow objectForKey:@"L_Name"] objectForKey:@"text"];
    NSString *Date = [[CurrentCommentRow objectForKey:@"date"] objectForKey:@"text"];
    NSString *Time = [[CurrentCommentRow objectForKey:@"Time"] objectForKey:@"text"];
    NSString *UserImagePath = [[CurrentCommentRow objectForKey:@"UserImage"] objectForKey:@"text"];
    NSString *TotalComments = (NSString*)[[CurrentCommentRow objectForKey:@"TotalComment"] objectForKey:@"text"];
    NSString *imageRelativePath = [UserImagePath substringFromIndex:[UserImagePath rangeOfString:@"/" options:NSBackwardsSearch].location];


    UIView *CommentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 297, 140)];

    NSString* imageURL = [NSString stringWithFormat:@"http://primehangout.com/Images/IPhone%@",imageRelativePath];
    NSURL* url = [NSURL URLWithString:imageURL];        
    HJManagedImageV *managedImage = [[HJManagedImageV alloc] initWithFrame:CGRectMake(10, 18, 56, 56)];
    managedImage.url = url;
    [self.objManager manage:managedImage];
    [CommentView addSubview:managedImage];

    UILabel *lblName = [[UILabel alloc] initWithFrame:CGRectMake(82, 18, 180, 11)];
    lblName.font = [UIFont boldSystemFontOfSize:12];
    lblName.textColor = [UIColor colorWithRed:(5.0/255.0) green:(102.0/255.0) blue:(202.0/255.0) alpha:255];
    lblName.text = [NSString stringWithFormat:@"%@:",FirstName];        
    [CommentView addSubview:lblName];
    [lblName release];

    UITextView *txtViewComment = [[UITextView alloc] initWithFrame:CGRectMake(73, 34, 180, 40)];
    txtViewComment.contentInset = UIEdgeInsetsMake(-10,0,0,0);
    [txtViewComment setEditable:FALSE];
    txtViewComment.font = [UIFont fontWithName:@"Arial" size:11];
    txtViewComment.text = Comment;
    txtViewComment.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    [CommentView addSubview:txtViewComment];
    [txtViewComment release];


    UILabel *lblDateTime = [[UILabel alloc] initWithFrame:CGRectMake(82, 79, 180, 20)];
    lblDateTime.font = [UIFont fontWithName:@"Arial" size:10];
    lblDateTime.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    lblDateTime.text = [NSString stringWithFormat:@"%@ %@",Date,Time];      
    [CommentView addSubview:lblDateTime];
    [lblDateTime release];

    UILabel *lblTotalComments = [[UILabel alloc] initWithFrame:CGRectMake(82, 95, 80, 20)];
    lblTotalComments.font = [UIFont fontWithName:@"Arial" size:11];
    lblTotalComments.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
    lblTotalComments.text = [NSString stringWithFormat:@"%@ Comments",TotalComments];       
    [CommentView addSubview:lblTotalComments];
    [lblTotalComments release];



    if ([TotalComments integerValue]>0) 
    {
        UIButton *btnViewAll = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnViewAll setFrame:CGRectMake(140, 82, 70, 45)];
        [btnViewAll setImage:[UIImage imageNamed:@"view_all_button_bg.png"] forState:UIControlStateNormal];
        //[lblViewAll setTitle:@"view all" forState:UIControlStateNormal];
        [btnViewAll addTarget:self action:@selector(ViewAllBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [btnViewAll setTag:(150 + indexPath.row)];
        [CommentView addSubview:btnViewAll];                    
    }
    else {
        [lblTotalComments setFrame:CGRectMake(82, 95, 150, 20)];
    }


    UIButton *btnAddComment = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnAddComment setFrame:CGRectMake(200, 82, 70, 45)];
    [btnAddComment setImage:[UIImage imageNamed:@"add_comment.png"] forState:UIControlStateNormal];
    [btnAddComment addTarget:self action:@selector(ViewAllBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [btnAddComment setTag:(1050 + indexPath.row)];
    [CommentView addSubview:btnAddComment];

    [cell.contentView addSubview: CommentView];

}



return cell;

}

After using above code the the scrolling becomes smooth and problem got solved but a new problem raised is that the duplicate content is being shown at random and all data get misguided for eg. the first cell is being shown 3-4 times and so on…

If anything is unclear feel free to ask friends.
🙂

  • 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-20T05:01:00+00:00Added an answer on May 20, 2026 at 5:01 am

    reusing is the way to go, but you are doing it wrong.
    Of course you have to set the new values after you’ve reused a cell.

    if (cell == nil) {
        // create new cell
        cell = ...
        UILabel *lblTotalComments = [[UILabel alloc] initWithFrame:CGRectMake(82, 95, 80, 20)];
        lblTotalComments.tag = 192;
        lblTotalComments.font = [UIFont fontWithName:@"Arial" size:11];
        lblTotalComments.textColor = [UIColor colorWithRed:(75.0/255.0) green:(75.0/255.0) blue:(75.0/255.0) alpha:255];
        [CommentView addSubview:lblTotalComments];
        [lblTotalComments release];
    
    }
    // configure cell
    UILabel *lblTotalComments = (UILabel *)[cell viewWithTag:192];
    lblTotalComments.text = [NSString stringWithFormat:@"%@ Comments",TotalComments];       
    

    you should get the idea how to implement this.

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

Sidebar

Related Questions

I am using the following code for the Share Price Application I have been
There are several people about (myself being one of them) who have been developing
People have been developing own solutions to the following problems: Consistent messaging frameworks for
I have been developing a C# windows form application in XP. It all works
I have been developing on the iPhone with Objective-C for a few months now
I have been developing a new JavaScript application which is rapidly growing in size.
I have been developing a BlackBerry application for about 7 months, and I have
Ok I've been developing iphone-apps for over a year now, but there's this one
I have been developing a quite large application, and I uploaded it to my
I have been developing websites for a couple of years now and I almost

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.