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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:52:27+00:00 2026-05-25T14:52:27+00:00

why do we use dequeueReusableCellWithIdentifier if the cells and section fill exactly the size

  • 0

why do we use dequeueReusableCellWithIdentifier if the cells and section fill exactly the size of the screen, or even less than the height of the screen : let’s say we have 2 sections with only 1 row for each?

example :

    switch (indexPath.section)
{
    case kMonitoringSection:
    {
        cell = [tableView dequeueReusableCellWithIdentifier:kMonitoringCellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kMonitoringCellIdentifier] autorelease];
            cell.textLabel.text = NSLocalizedString(@"Monitoring", @"");

            UISwitch *switchCtl = [[[UISwitch alloc] initWithFrame:CGRectMake(197, 8, 94, 27)] autorelease];
            [switchCtl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            switchCtl.backgroundColor = [UIColor clearColor];

            [cell.contentView addSubview:switchCtl];
        }

        break;
    }

    case kLevelSection:
    {
        cell = [tableView dequeueReusableCellWithIdentifier:kLevelCellIdentifier];
        UILabel *levelLabel = nil;
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kLevelCellIdentifier] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.text = NSLocalizedString(@"Level", @"");

            levelLabel = [[[UILabel alloc] initWithFrame:CGRectMake(171, 11, 120, 21)] autorelease];
            levelLabel.tag = kLevelTag;
            levelLabel.textAlignment = UITextAlignmentRight;
            [cell.contentView addSubview:levelLabel];
            levelLabel.backgroundColor = [UIColor clearColor];
        }

in the sample code : BatteryStatus

if we had 20 rows, i would understand the point, but i’m not sure here…

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-25T14:52:27+00:00Added an answer on May 25, 2026 at 2:52 pm

    If you only have a static number of cells, say only two (different) cells in your tableView and no cell is repeated, you should instead instanciate your two cells in your XIB (and design them there with your UISwitch for the first one and your custom UILabel for the other) and point an IBOutlet to it.

    Much simpler, less code, and totally makes sense when no reuse of the cells is needed.

    Do read Apple’s Table View Programming Guide which is a really great resource (like quite every Programming Guide in Apple’s doc) and explains all this in details. In particular the part “The Technique for Static Row Content“ explains this exact use case.


    So of course you can use dequeueReusableCellWithIdentifier in such case, it won’t hurt (and probably in the BatteryStatus sample they did it because they didn’t wonder if it was really useful or not, just as an habit because they do this all the time when they have more rows), but it is not the best way to do it.

    Note that sample codes provided by Apple are not always the solution to follow: they are just one way to do sthg, and especially the sample generally tend to focus on the fonctionnality it wants to test (in this case the Battery Status) and does not worry about anything else (especially performance — except if the sample is about performance of course).

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

Sidebar

Related Questions

I have problem with using dequeueReusableCellWithIdentifier method. Whenever I use this one, one cell
Let's say I have a UITableView that is part of an iPad app doesn't
I have an heterogeneous tableView with an entire section made up of UITableViewCells with
So I have a UITableView which should loop through a single NSMutableArray and use
I have an NSMutableArray with objects within it and I use the following code
I have a UITextField that I am adding to a UITableViewCell to use as
I have a table into wich I'd like to mix some custom cells and
I have performance issue in UITableView scrolling when I use imageWithContentsOfFile instead of imageNamed.
I have a problem and lots of difficulty finding a solution, even if I
I have a UITableView in which of course I use some UITableViewCells. Now some

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.