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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:03:27+00:00 2026-05-27T21:03:27+00:00

I run my animations in a UITAbleViewCell. Each cell has its own animation and

  • 0

I run my animations in a UITAbleViewCell.
Each cell has its own animation and the cells are reusable.
I use [mView performSelectorInBackground:@selector(layoutSubview) withObject:nil];

There in the background thread I initiate the runLoop to perform tasks like this:

- (void)startAnimation 
{
    NSRunLoop *mLoop = [NSRunLoop currentRunLoop];
    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];

    mRunLoop = YES;
    while (mRunLoop == YES && [mLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]);
}

and stop it:

- (void)stopAnimation 
{
    if (![NSThread isMainThread]) {
        [[NSThread currentThread] cancel];
    }

    mRunLoop = NO;
    self.animationTimer = nil;
    CFRunLoopStop(CFRunLoopGetCurrent());   
}

I run into problems when I fast scroll through table, because on the first cell initiation I begin the animation, so the first runLoop call occures which performs a setNeedDisplay and all the methods from it. But before finishing the first runLoop cycle the cell disappears from the view and is already available for reuse. So I begin clearing it, while the cycle is still performing operations and here I meet situations like

message sent to deallocated instance

So could you please give me some hints of how should I correctly stop performing the operations in that thread? I mean if I want to realese for example an object, which is performing some actions how to immediately stop’em?

Hope I gave enough info.
Thanks

UPDATE: No ideas at all?

  • 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-27T21:03:28+00:00Added an answer on May 27, 2026 at 9:03 pm

    I’ll take a completely different stab on it:

    Get rid of the cell’s timers and background threads altogether!

    Animation is not something where NSTimer is a good fit in the first place and having multiple timers won’t help much, either.

    UITableView has a method visibleCells and a method indexPathsForVisibleRows. I’d suggest to use a single CADisplayLink — which is suited for animation, as it calls you back with the actual refresh rate of the display or a fraction thereof — in your tableview-controller and in the callback of that display-link iterate over the visible cells.

    If you want to schedule the display-link on the run-loop of a secondary thread, feel free to do so, but I’d check if you can get away without extra threading first.

    Some code:

    @interface AnimatedTableViewController ()
    
    @property (strong, nonatomic) CADisplayLink *cellAnimator;
    - (void)__cellAnimatorFired:(CADisplayLink *)animator;
    
    @end
    
    @implementation AnimatedTableViewController
    
    @synthesize cellAnimator = cellAnimator_;
    
    - (void)setCellAnimator:(CADisplayLink *)animator
    {
        if (animator == cellAnimator_)
            return;
    
        [cellAnimator_ invalidate];
        cellAnimator_ = animator;
    
        [cellAnimator_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSCommonRunLoopModes];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        self.cellAnimator = [CADisplayLink displayLinkWithTarget:self selector:@selector(__cellAnimatorFired:)];
        ...
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        self.cellAnimator = nil;
        ...
    
        [super viewWillDisappear:animated];
    }
    
    - (void)__cellAnimatorFired:(CADisplayLink *)animator
    {
         NSArray *visibleCells = [self.tableView visibleCells];
         [visibleCells enumerateObjectsUsingBlock:^(UITableViewCell *cell, NSUInteger unused, BOOL *stop){
             [cell setNeedsDisplay];
         }];
    }
    
    ...
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into an animation issue (I think) with my TabBar based app. I
I'm new to iPhone development, and doing some experimentation with Core Animation. I've run
I run a rather complex project with several independent applications. These use however a
How can I overwrite the CSS below with jQuery? (The animations aren't being run
I am trying to run a Walk style animation on my main game sprite.
I have a web page with animations ( JQuery Animation ) all over the
Here's my dilemma. I have 2 animations that need to run sequentially. The first
I am using VS 2010 to create a simple animation, however run-time getting following
I have a group of fade out animations, after which I want to run
Can I ever run into block retain cycle with animateWithDuration:animations:completion: ? If yes, then

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.