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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:17:13+00:00 2026-06-07T05:17:13+00:00

Not much code here, but this problem is seriously annoying me! .h: @interface processController

  • 0

Not much code here, but this problem is seriously annoying me!

.h:

@interface processController : UIViewController {
         NSTimer *timer;
}
@property (nonatomic, retain) NSTimer *timer;

.m:

- (void)viewDidLoad {
    [super viewDidLoad];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector (main) userInfo:nil repeats:YES];
}
- (void)main {
    NSLog(@"testing");
}
- (void)viewDidUnload {
    [self.timer invalidate];
    self.timer = nil;
}

The weird thing is, when I fire this code:

ViewController *main = [[ViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:main animated:YES];

and switch views, the timer keeps firing! What am I doing wrong?

  • 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-07T05:17:15+00:00Added an answer on June 7, 2026 at 5:17 am

    viewDidUnload is not called when the view is removed from the screen but only when a memory warning is received by the application. It’s not called when the UIViewController is deallocated either. From Apple’s documentation:

    When a low-memory condition occurs and the current view controller’s
    views are not needed, the system may opt to remove those views from
    memory. This method is called after the view controller’s view has
    been released and is your chance to perform any final cleanup. If your
    view controller stores separate references to the view or its
    subviews, you should use this method to release those references. You
    can also use this method to remove references to any objects that you
    created to support the view but that are no longer needed now that the
    view is gone. You should not use this method to release user data or
    any other information that cannot be easily recreated.

    You most likely meant to use viewWillDisappear

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        [self.timer invalidate];
        self.timer = nil;
    }   
    

    You probably want to start your timer in the viewWillAppear: as viewDidLoad is called as soon as the controller’s view property is accessed. Not nercessarely when the view is shown.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(main) userInfo:nil repeats:YES];
    }
    

    I’d recommend reading the discussions for viewDidLoad and viewDidUnload as well as viewWillAppear and viewWillDisappear from the UIViewController documentation.

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

Sidebar

Related Questions

I've searched a lot but could not solve this problem. I am generating PDF
Not sure how to word this but my problem is that my fields will
Not much code since I'm a bit at a loss on how to start.
i am using the MVVM design pattern and do not want much code in
I've not had to write much batch file code in the past and I'm
not much of a programming question, but development related still, I'm starting Android development
Not much to say about this question...
I'm not much of a programmer but I want to integrate http://storify.com/ into my
Please can anyone help me out with this problem? This code below works perfectly
I'm a novice programmer. This may be a simple problem but I've never seen

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.