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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:27:31+00:00 2026-05-24T23:27:31+00:00

hi i am trying to add uilabel in a group table .The approach i

  • 0

hi i am trying to add uilabel in a group table .The approach i have used is that my whole logic for cell creation is in uitableviewcellforrowatindexpath ie; i have not use seperate class(eg:customcell.h or something like that).
i am succesful in adding the labels BUT CUSTOM CHANGES ARE REFLECTING ONLY TO SECTION ZERO’S ROW.
then i try if(indexpath.section==0) and if(indexpath.section==1) still changes are reflecting only to section zero rows only.Also there is no need of if clause because all the cells look and feel is same.
here is my code:

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
//code STATS here : initializing here for cells background view & selection back ground view     
    cell.backgroundView =
    [[[UIImageView alloc] init] autorelease];
    cell.selectedBackgroundView =
    [[[UIImageView alloc] init] autorelease];

    //code ENDS HERE of initializing
    //custom label

    UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
    cell.accessoryView =
    [[[UIImageView alloc]
      initWithImage:indicatorImage]
     autorelease];

    const CGFloat LABEL_HEIGHT = 20;
    UIImage *image = [UIImage imageNamed:@"filter.png"];//this image is on top //left of section zero rows

    //
    // Create the label for the top row 
    //

        topLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     image.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT),
                     aTableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)]
         autorelease];
        [cell.contentView addSubview:topLabel];

        //
        // Configure the properties for the text that are the **SAME** on every row
        //
        topLabel.tag = TOP_LABEL_TAG;
        topLabel.backgroundColor = [UIColor clearColor];
        topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
        //testing:
        topLabel.text=@"test1";
        //
        // Create the label for the top row of text
        //
        bottomLabel =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     image.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT) + LABEL_HEIGHT,
                     aTableView.bounds.size.width -
                     image.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)]
         autorelease];
        [cell.contentView addSubview:bottomLabel];

        //
        // Configure the properties for the text that are the same on every row
        //
        bottomLabel.tag = BOTTOM_LABEL_TAG;
        bottomLabel.backgroundColor = [UIColor clearColor];
        bottomLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        bottomLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        bottomLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize] - 2];
        bottomLabel.text=@"test2";
    }


    //testing for section 2
    //this image is on top left of section one rows
        UIImage *image1 = [UIImage imageNamed:@"akshardham.jpg"];
        topLabel1 =
        [[[UILabel alloc]
          initWithFrame:
          CGRectMake(
                     image1.size.width + 2.0 * cell.indentationWidth,
                     0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT),
                     aTableView.bounds.size.width -
                     image1.size.width - 4.0 * cell.indentationWidth
                     - indicatorImage.size.width,
                     LABEL_HEIGHT)]
         autorelease];
        [cell.contentView addSubview:topLabel1];

        topLabel1.tag = TOP_LABEL_TAG1;
        topLabel1.backgroundColor = [UIColor clearColor];
        topLabel1.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        topLabel1.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        topLabel1.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
        //testing:
        topLabel1.text=@"test2section";
    }


}

else
{
    topLabel = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG];
    bottomLabel = (UILabel *)[cell viewWithTag:BOTTOM_LABEL_TAG];
    topLabel1 = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG1];
}

any suggestion?thanks..

  • 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-24T23:27:32+00:00Added an answer on May 24, 2026 at 11:27 pm

    it’s like your whole code is in

    if (cell == nil) {
    
    }
    

    So you won’t go in when you will scroll because you will have enough cells wich are created. You will reuse them and the cell won’t be nil and you won’t go in your customization code.

    Do:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
        static NSString * MYTableViewCellIdentifier = @"MYTableViewCellIdentifier";    
    
        MyTableViewCell * cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:MYTableViewCellIdentifier];    
        if (cell == nil) { 
            // Create the cell
            // Global layout for the cell        
        }    
        // Customization code    
        return cell;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a UITableViewCell, and i am trying to add an animation that causes
I'm trying to add an extra UILabel into each cell( UITableView ) I'v succeeded
I have two animations that I'm trying to perform on a UILabel on the
I am trying to add a UITapGestureRecognizer to a UILabel that will animate down
I'm trying to add a UILabel to my UIScrollView , but it doesn't show
Im trying to add views inside custom UITableViewCells. I tried using the [cell.contentView addSubview]
I am trying add two columns in a text file that are seperated by
I am trying to add a UILabel in UIWindow of AppDelegate from a UIViewController.
I'm trying to add some UI elements like UIProgressView , UILabel , UIButton and
I'm trying to add a feature into my app that allows the user to

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.