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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:24:37+00:00 2026-06-15T02:24:37+00:00

I have a UITableViewCell subclass which contains a UIStepper. When the user interacts with

  • 0

I have a UITableViewCell subclass which contains a UIStepper. When the user interacts with the stepper, I fire off an NSTimer so that the stepper will save its value and write to Core Data if the value is not changed again within 2 seconds.

To put it another way:

UIStepper is contained within UITableViewCell.
User can change stepper value up and down.
Each touch triggers timer with 2 second delay.
Each subsequent touch invalidates the timer.
When stepper has been left alone for 2 seconds, changes are saved.

This works very well for what I need it for. The problem is that if my user is very quick and they change the value, then pop the view controller and go to do something else, the 2 second timer still hasn’t fired and the data is not up to date for the next action.

To keep things as simple as possible, I need to be able to tell within that table view cell if the (table) view is getting popped. Then I can expedite the saving process and ensure data is up to date and saved before any other actions take place.

  • 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-15T02:24:38+00:00Added an answer on June 15, 2026 at 2:24 am

    If you want to tell if the table has been popped, put your cleanup/save method in the viewWillDisappear method. Because you’re using timers, you do not want to do it it dealloc, so you don’t have any unintended strong reference cycles.

    It’s not clear from your question, but I would want to make sure that you’re not putting your NSTimer on your UITableViewCell cells. Obviously, it’s a model issue, not a view issue, but also table views do all sorts of optimizations for dequeue and reusing table view cells.

    Second, what ever object class you have to keep track of your data (I call it ModelDataItem) should provide not only the mechanism to save, to use the timers, etc., but also a mechanism to force the save of any pending records (which I do through a boolean needSave). So, to support that, in my mind, you ModelDataItem probably should have at least the following four items:

    (a) a reference to its own timer;

    @property (nonatomic, strong) NSTimer *timer;
    

    (b) a flag that indicates whether the record has a pending save operation

    @property (nonatomic) BOOL needSave;
    

    (c) a method that you call whenever the object’s values change (e.g. the value was incremented) to schedule the save in 2 seconds:

    - (void)scheduleSave
    {
        self.needSave = YES;
    
        if (self.timer)
            [self.timer invalidate];
    
        self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0
                                                      target:self
                                                    selector:@selector(save)
                                                    userInfo:nil
                                                     repeats:NO];
    }
    

    (d) you need the method that the timer calls that actually saves the record:

    - (void)save
    {
        // do whatever you need to save the record
    
        NSLog(@"%s saving value=%@", __FUNCTION__, self.value);
    
        // now let's clean up the timer
    
        if (self.timer)
        {
            [self.timer invalidate];
            self.timer = nil;
        }
    
        self.needSave = NO;
    }
    

    Then, in your table view controller, you should:

    (a) when the stepper’s UIControlEventValueChanged is called, you should obviously change your data model and then call the above ModelDataItem method scheduleSave;

    (b) when the table view is being dismissed, should presumably promptly save anything pending:

    for (ModelDataItem *item in allModelDataItems)
    {
        if (item.needSave)
            [item save];
    }
    

    Note, on that last point, I do not rely on dealloc to clean up and save the model items that need saving, because a scheduled NSTimer retains its target and thus the dealloc won’t get call (or at least not until the timer is performed). So, I manually iterate through them and take care of that when I dismiss the view.

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

Sidebar

Related Questions

I have a subclass of UITableViewCell which contains several elements - UIImageViews, Labels, etc.
I have a UITableViewCell subclass which draws a rectangular vertical line of 5px width
I have a UISwitch inside a custom UITableViewCell (the subclass of which I call
I am working in a class that is a subclass of UITableViewCell and have
I have created a custom subclass of UITableViewCell. There, I allow the user to
Similar to this question I have a custom subclass of UITableViewCell that has a
I have a custom view class which is a subclass of UITableViewCell. I have
I have created a class named ListCell which is a subclass of UITableViewCell .
I have a custom-subclassed UITableViewCell which will include a few labels, to which I
So I have a UITableViewCell subclass that needs to know whether the UITableView is

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.