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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:51:14+00:00 2026-06-16T22:51:14+00:00

I m trying to add cells to a tableView – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath

  • 0

I m trying to add cells to a tableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *MyIdentifier = @"MyIdentifier";
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        [cell setSelectionStyle:UITableViewCellEditingStyleNone];
        // Set up the cell

        cell.backgroundColor = [UIColor clearColor];
        UIButton *buyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImageView *img;
        UILabel *lbl;
        UIImageView *backImage;
        UILabel *textLabel;
        UILabel *detailTextLabel;

        NSInteger val = [indexPath row] * 3;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            //*buyBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
            [buyBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

            //*img = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
            [img setImage:[UIImage imageNamed:@""]];
            //*lbl = [[UILabel alloc] initWithFrame:CGRectMake(x,y,w,h)];
        }
        else
        {
            backImage =  [[UIImageView alloc] initWithFrame:CGRectMake(2, 4, 316, 62)];
            [buyBtn setFrame:CGRectMake(257, 100, 57, 24)];
            img = [[UIImageView alloc] initWithFrame:CGRectMake(257, 75, 57, 24)];

            lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 57, 24)];
            textLabel = [[UILabel alloc] initWithFrame:CGRectMake(4, 4, 230, 25)];
            detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(4, 25, 230, 30)];

            backImage.image = [UIImage imageNamed:@"shop-bg.png"];
            [buyBtn setImage:[UIImage imageNamed:@"buy_button"] forState:UIControlStateNormal];
            [img setImage:[UIImage imageNamed:@"price_button.png"]];

            lbl.center = img.center;
            lbl.textAlignment =  UITextAlignmentCenter;
            lbl.text = [self.original_List objectAtIndex:val+2];
            lbl.backgroundColor = [UIColor clearColor];

            textLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:14];
            textLabel.backgroundColor = [UIColor clearColor];
            textLabel.text = [self.original_List objectAtIndex:val];

            detailTextLabel.text = [self.original_List objectAtIndex:val+1];
            detailTextLabel.backgroundColor = [UIColor clearColor];
            detailTextLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:10];
            textLabel.textColor = [UIColor blackColor];
            detailTextLabel.textColor = [UIColor whiteColor];
            detailTextLabel.numberOfLines = 2;
        }

        [buyBtn setTag:[indexPath row]];
        [buyBtn addTarget:self action:@selector(buyBtnPressed:) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:backImage];
        [cell addSubview:detailTextLabel];
        [cell addSubview:textLabel];
        [cell addSubview:buyBtn];
        [cell addSubview:img];
        [cell addSubview:lbl];

        return cell;
    }

From figure it can be seen that The first Cell DOES NOT Contain the added image, label and button, however if other cells are scrolled those who lost view turn transparent while those who are in view are okay.

Why is my three subview not getting added from first cell, my textLabel and detailTextLabel are added as they should.

enter image description here

  • 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-06-16T22:51:16+00:00Added an answer on June 16, 2026 at 10:51 pm

    First of all you don’t dequeue the cell and always create a new one without reusing. Try adding something like this (not sure if you need autorelease, depends on weather you use ARC or not):

    RecentsTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
            cell = [[[RecentsTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                reuseIdentifier:cellIdentifier] autorelease];
    }
    

    Second, if you are not using ARC (auto ref counting) then you have bunch of lost refs here.

    [[Class alloc] init] adds the ref and addSubview also adds the ref. I’m wondering what xcode “analyse” build says on this.

    Third, imho all labels you added to the cell need also their “frame” property to set up, not just number of lines, etc.

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

Sidebar

Related Questions

I am trying to add a row to a tableview using NSIndexPath *indexPath =
I'm trying to add thumbnails into cells in UITableView cell.imageView.image = [UIImage imageNamed: @TestThumbnail.jpg];
I am trying to programatically add a UITextFiled inside one of my tableview cells.
I'm trying to add an extra UILabel into each cell( UITableView ) I'v succeeded
I'm trying to add a subview to a tableview cell and of course using
I am trying to add button into my table cell like below: - (UITableViewCell
I am working on custom cell in uitableview and trying to add uilabels in
I'm trying to add a new cell to a tableview, and pop up an
I am trying to add custom labels to my cell in UITableView. When I
I'm trying to add a ViewController to my TableView cell however it is not

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.