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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:32:36+00:00 2026-06-12T10:32:36+00:00

I’m trying to create a UITableView which loads a custom cell from a XIB.

  • 0

I’m trying to create a UITableView which loads a custom cell from a XIB. I have EventsCell.xib along with the .m and .h files.

The cell’s content and height are dynamic, as it can contain an unknown number of subviews.

This is the code that loads the cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"EventsCellIdentifier";

        EventsCell *cell = (EventsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) 
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"EventsCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];        
        }

        NSDictionary *hour = [[[eventsArray objectAtIndex:[indexPath section]] valueForKey:@"hours"] objectAtIndex:[indexPath row]];

        NSArray *events = [hour valueForKey:@"events"];

        cell.events = events;
        cell.timeLabel.text = [hour valueForKey:@"name"];

        int offset = 0;
        for(NSDictionary *event in events)
        {
            UIView *vvv = [[UIView alloc] initWithFrame:CGRectMake(50, offset, 270, 44)];
            [vvv setBackgroundColor:[UIColor clearColor]];

            UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
            lab.text = [event valueForKey:@"name"];
            lab.backgroundColor = [UIColor clearColor];

            [vvv addSubview:lab];

            [cell.contentView addSubview:vvv];

            offset += 44;
        }    

        return cell;
    }

It loads the cells, but after i scroll a few times on the table view, the content looks like this:

enter image description here

What am i doing wrong?..

Thank you!

==================== UPDATE ====================

Now another thing is happening.
I’ve added all of the elements of the subviews i add to the cell in a separate view controller. Like bellow.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"EventsCellIdentifier";

        EventsCell *cell = (EventsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) 
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"EventsCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];        
        }

        for (UIView *subV in [cell.contentView subviews]){
            [subV removeFromSuperview];
        }    

        NSDictionary *hour = [[[eventsArray objectAtIndex:[indexPath section]] valueForKey:@"hours"] objectAtIndex:[indexPath row]];

        NSArray *events = [hour valueForKey:@"events"];

        cell.events = events;
        cell.timeLabel.text = [hour valueForKey:@"name"];

        int offset = 0;

        for(NSDictionary *event in events)
        {
            EventBoxViewController *ebvc = [[EventBoxViewController alloc] initWithNibName:@"EventBoxViewController" bundle:nil];
            ebvc.nameLabel.text = [event valueForKey:@"name"];

            [ebvc.view setFrame:CGRectMake(50, offset, 270, 44)];
            [cell.contentView addSubview:ebvc.view];

            offset += 44;
        }    

  return cell; 
 }

And they don’t load as they should. Please see the image below.

enter image description here

They load only when i scroll through the cells and even then they don’t load as they should.
Also the text for the label does not get assigned.
Any ideas on what i am doing wrong?

Thank you.

  • 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-12T10:32:36+00:00Added an answer on June 12, 2026 at 10:32 am

    Views are added on cell.contentView, Since the cells are reuable it still remains added,
    If we remove all the subViews it will work

    for (UIView *subV in [cell.contentView subviews]){
         [subV removeFromSuperview];
    }
    

    Add the above code after

    if (cell == nil) 
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"EventsCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post

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.