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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:16:33+00:00 2026-06-02T10:16:33+00:00

So I have the following code: static NSString *CellIdentifier = @RecommendationCell; UITableViewCell *cell =

  • 0

So I have the following code:

static NSString *CellIdentifier = @"RecommendationCell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableViewCell"] autorelease];
    }

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [indicator setCenter:CGPointMake(0, 15)];
    [indicator startAnimating];
    [indicator hidesWhenStopped];

    UILabel *someLabel......... 


    UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
    [containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    [containerView setAutoresizesSubviews:YES];
    [containerView setBackgroundColor:[UIColor clearColor]];
    [containerView addSubview:indicator];
    [containerView addSubview:someLabel];
    [containerView setFrameSize:CGSizeMake(indicator.frameWidth+self.loadingGeniusLabel_.frameWidth, 30)];
    [containerView setCenter:CGPointMake(cell.contentView.center.x, 15)];

    [cell.contentView addSubview:containerView];

    [indicator release];
    [containerView release];

    return cell;

My question is, is the code above efficient/clean? The reason I ask is because if the cell that we get is from the reusable deck, then it would have the UIActivityIndicator and the necessary view in it right? Do I just have to add the subviews only if I am allocating a new cell (i.e: when the cell == nil)?

  • 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-02T10:16:34+00:00Added an answer on June 2, 2026 at 10:16 am

    is the code above efficient/clean?

    No

    if the cell that we get is from the reusable deck, then it would have the UIActivityIndicator and the necessary view in it right

    Yes, but since you are using the generic UITableViewCell, you won’t be able to access the UIActivityIndicator after adding it once. You’ll need to create a subclass of UITableViewCell to do this efficiently.

    Do I just have to add the subviews only if I am allocating a new cell (i.e: when the cell == nil)?

    Yes

    Only call addSubview outside of the if (cell == nil) block if you absolutely need to, it’s an expensive method call and will seriously impact your frames per second when scrolling the table.

    Your best bet is subclassing UITableViewCell. That way, any objects/UIViews (or UIView subclasses) that you need to control the value/behavior of differently from cell to cell are better suited as properties on the UITableViewCell subclass. By doing this, you can instantiate them either in the xib file, or in the cell setup (inside that if statement), and then simply change the values for each cell (rather than creating the new objects each time).

    Apple’s Table View Programming guide discusses this in depth:
    http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//apple_ref/doc/uid/TP40007451

    Apple’s sample project shows a couple different ways for managing table cells efficiently:
    https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html

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

Sidebar

Related Questions

I have the following code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString
I created a UITableView and wrote the following code in cellForRowAtIndexPath static NSString *CellIdentifier
I have the following code: - (CGFloat)tableView:(UITableView *) tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{ TestCell* cell
I have following code: public static void ProcessStep(Action action) { //do something here if
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: class Program { static void Main(string[] args) { new
Say I have the following code: class Parent { static string MyField = ParentField;
Assume that we have the following code: class Program { static volatile bool flag1;

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.