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

  • Home
  • SEARCH
  • 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 9137433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:10+00:00 2026-06-17T09:06:10+00:00

I am trying to put a cell as a space between each cell –

  • 0

I am trying to put a cell as a space between each cell – which will be hidden by setting alpha = 0. In my table, the space cells will be for rows that are odd.

Note that the actual cell height is 85, but the hidden cell height (ie space between cells) is 20.

The problem is that the space cell height is 85, but not 20, I don’t know why. Maybe the cell is not loaded correctly.

Cell here is the UITableViewCell – the actual cell – with identifier ‘Cell’.

Cell2 is the space with identifier ‘Space’.

Each class above has its own UITableViewCell class and the XIB files are also assigned to each of them. The identifier is also set in the IB for each Xib.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier1 = @"Cell";
static NSString *CellIdentifier2 = @"Space";

Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

if(!cell)
{
    NSArray *ar = [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:nil options:nil];
    for (id obj in ar)
    {
        if ([obj isKindOfClass:[Cell class]])
        {
            cell = (Cell *)obj;
            break;
        }
    }
}

if (indexPath.row % 2 == 1)
{
    Cell2 *cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

    if (!cell2)
    {
        NSArray *ar = [[NSBundle mainBundle] loadNibNamed:@"Cell2" owner:nil options:nil];
        for(id obj in ar)
        {
            if([obj isKindOfClass:[Cell2 class]])
            {
                cell2 = (Cell2 *)obj;
                break;
            }
        }

        // Method 1
        cell2 = [[Cell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
         // Method 2
        //cell2 = [[Cell2 alloc] init];
        // Method 3
        //cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

        [cell2.contentView setAlpha:0];
        // prevent selection and other stuff
        [cell2 setUserInteractionEnabled:NO];
    }
    return cell2;
}
else
{
    // Configure the actual cell
}


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-06-17T09:06:11+00:00Added an answer on June 17, 2026 at 9:06 am

    * I’ve renamed some of your NIB/Class names for a better understanding. *

    First, you should register each cells’ NIB:

    - (void)viewDidLoad{
        [super viewDidLoad];
    
        static NSString *CellIdentifier1 = @"ContentCell";
        static NSString *CellIdentifier2 = @"SpaceCell";
    
        UINib *nib = [UINib nibWithNibName:@"CellViewNIBName" bundle:nil];
        [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier1];
    
        nib = [UINib nibWithNibName:@"CellSpaceNIBName" bundle:nil];
        [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier2];
    
        self.contentView.hidden = YES;
        [self loadData];
    }
    

    Because you have the NIBs registered, dequeueReusableCellWithIdentifier: will always return a cell:

    - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath      *)indexPath
    {
        static NSString *CellIdentifier1 = @"ContentCell";
        static NSString *CellIdentifier2 = @"SpaceCell";
    
        // Space Cell
        if (indexPath.row % 2 == 1) {
            CellSpace *cell = (CellSpace *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
            return cell;
        }
    
        // Content cell
        else {
            CellView *cell = (CellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
            // Configure cell
            return cell;
        }
    }
    

    Last, but not least, make sure to implement the following delegate method:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Space cell's height
        if (indexPath.row % 2 == 1) {
            return 20.0f;
        }
    
        // Content cell's height
        else {
            return 80.0f;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put a large table in a pdf file which will be
I am trying to fetch my mysql records into a table, each cell must
Trying to put a regex expression together that returns the string between _ and
I trying to put together an Android app that will take a picture and
I'm trying to put together a GUI for setting some pricing. There are three
I'm trying to examine on which rows a particular value is located in a
I have a table cell with a text box in it, and I'm trying
I've got the following code which should put an image in the top section/cell
I am reading a table row from one page, and then trying to put
I'm trying to put together a simple table that shows my model's data. I

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.