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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:34:18+00:00 2026-06-01T16:34:18+00:00

I am doing some heavy calculations when I am creating cells. I am trying

  • 0

I am doing some heavy calculations when I am creating cells. I am trying to figure out the best way to keep the UITableView fluid, but at the same type do the calculations on the background (keep the UI thread without too much processing).

For testing purposes only, I am using this as my heavy calculation method:

+(NSString*)bigCalculation
{
    int finalValue=0;
    int j=0;
    int i=0;

    for (i=0; i<1000; i++) {
        for (j=0; j<10000000; j++) {
            j++;
        }
        finalValue+=j/100*i;
    }

    return [NSString stringWithFormat:@"%d",finalValue];
}

Inside the cellForRowAtIndexPath, I am only doing the following:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier=@"identifier";

    UITableViewCell *cell=nil;
    cell=[aTableView dequeueReusableCellWithIdentifier:identifier];
    if(!cell)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }

    NSString *text=[dataSource objectForKey:[[dataSource allKeys] objectAtIndex:indexPath.row]];


    dispatch_queue_t a_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
;
    dispatch_async(a_queue, ^{

        NSString *subtitle=[CalculationEngine bigCalculation];
        dispatch_async(dispatch_get_main_queue(), ^{
            [[cell detailTextLabel] setText:subtitle];
            dispatch_release(a_queue); 
        });
    });


    [[cell textLabel] setText:text];
    return cell;
}

At the moment I have the UITableView fluid, while in the background everything is working ok. So my questions are:

1) Is this the best way to achieve what I want, could KVO be the answer as well?

2) Before doing this:

dispatch_queue_t a_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);

I was doing:

dispatch_queue_create("com.mydomain.app.newimagesinbackground", DISPATCH_QUEUE_SERIAL)

And the performance was very poor. Could you explain me why?

  • 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-01T16:34:19+00:00Added an answer on June 1, 2026 at 4:34 pm

    This isn’t a good approach. You’re breaking MVC here by pushing the calculation work into the view controller. You should keep your data in model objects and manage the calculations there. The table view should then just display the current value from the model, using reloadRowsAtIndexPaths:withRowAnimation: when the data changes. KVO is one reasonable way to determine when the data changes.

    If you want to be lazy in calculations, then you can make calls to the model like recalculateIfNeeded to let the model know that someone (the table view in this case) would like a fresh value. You shouldn’t recalculate if the input data hasn’t actually changed, however. The model is where to keep track of whether the data has changed.

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

Sidebar

Related Questions

I am doing some heavy lifting in an SQL database, from C#. I keep
I'm creating a web application that does some very heavy floating point arithmetic calculations,
I'm trying to create a background process for some heavy calculations from the main
I am doing some heavy calculations with Python (using OpenCV and Numpy) and in
I basically have a unix process running and it is doing some heavy processing
I'm doing some heavy processing (building inverse indices) using ints/ longs in Java. I've
I've been doing some Web-Projects lately that rely on heavy Data-Binding and have been
I m trying to find the best way to build my UI based on
I'm doing some heavy image manipulation in php and I would like to show
I am developing an Android app and I am doing some heavy work (bringing

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.