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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:37:59+00:00 2026-06-13T16:37:59+00:00

I am new to iPhone Development, and am making a countdown project using navigation

  • 0

I am new to iPhone Development, and am making a countdown project using navigation controller and storyboard. My application has two views. The first view only has one button. When this button is clicked, it goes to the second view. The second view has the countdown objects. My problem is that when the countdown is running in second view, if I go back to first view and then hit the button to go to the second view, the countdown is no longer running.

Here is the code:

view1.h

#import <UIKit/UIKit.h>
#import "view2.h"

@interface view1: UIViewController

-(IBAction)nextpage:(id)sender;

@end

view1.m

@implementation view1


-(IBAction)nextpage:(id)sender
{
    view2 *next=[self.storyboard instantiateViewControllerWithIdentifier:@"secondview"];
    [self.navigationController pushViewController:next animated:YES];
}

@end

view2.h

@interface view2 : UIViewController
{
    IBOutlet UILabel *lbl;
    IBOutlet UITextField *field;

    NSTimer *theTimer;
    NSDate *targetDate;
    NSCalendar *cal;
    NSDateComponents *components;
}

@property (nonatomic,retain) IBOutlet UILabel *lbl;
@property (nonatomic,retain) IBOutlet UITextField *field;
-(IBAction)back_first_view;
@end

view2.m

@implementation view2
@synthesize lbl,field;

- (void)viewDidLoad
{
    cal = [[NSCalendar currentCalendar] retain];
    components = [[NSDateComponents alloc] init];
}

- (IBAction)buttonPressed:(id)sender {

    if (theTimer != nil) {
        return;
    }

    NSString *input = field.text;
    NSArray *timeSplit = [input componentsSeparatedByString:@":"];
    NSUInteger hours =  [[timeSplit objectAtIndex:0] intValue];
    NSUInteger minutes =  [[timeSplit objectAtIndex:1] intValue];
    NSDate *now = [NSDate date];
    NSDateComponents *dateComponents = [cal components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:now];
    [dateComponents setHour:hours];
    [dateComponents setMinute:minutes];

    if (!targetDate) {
        targetDate = [[cal dateFromComponents:dateComponents] retain];
    }
    else {
        targetDate = nil;
        targetDate = [[cal dateFromComponents:dateComponents] retain];
    }

    if ([targetDate timeIntervalSinceNow] > 0) {
        theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:YES];
        [self hideKeyboard];
    }
    else {
        targetDate = nil;
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Cannot countdown because time is before now" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

- (void)tick {
    if ([targetDate timeIntervalSinceNow] <= 0) {
        //Checks if the countdown completed

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Countdown Completed" message:@"YAY! The countdown has complete" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];

        return;
    }
    components = [cal components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:[NSDate date] toDate:targetDate options:0];

    NSInteger hours = [components hour];
    NSInteger minutes = [components minute];
    NSInteger seconds = [components second];

    NSString *output = [NSString stringWithFormat:@"%i Hours\n%i Minutes\n%i Seconds\n", hours, minutes, seconds];
    lbl.text = output;
}

- (void)hideKeyboard {
    if ([field isFirstResponder]) [field resignFirstResponder];
}

- (IBAction)back_first_view
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
 @end
  • 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-13T16:38:01+00:00Added an answer on June 13, 2026 at 4:38 pm

    Change this method to,

    - (IBAction)nextpage:(id)sender
    {
        [self.navigationController pushViewController:self.next animated:YES];
    }
    

    And add the first line to your viewDidLoad or any such methods,

    - (void)viewDidLoad {
           [super viewDidLoad]; //Always keep super call as first call in a method
           self.next = [self.storyboard instantiateViewControllerWithIdentifier:@"secondview"];
        // Do any additional setup after loading the view.
    }
    

    And declare next in .h file @interface as,

    @interface view1 : UIViewController
    {
    
    }
    @property (nonatomic, strong) view2 *next;
    

    Each and and every time when you are going to next page, you were creating a new view2, which you need to change.

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

Sidebar

Related Questions

I am new on iPhone development. I am making an app, using sqlite3 for
I am new iphone development. In my app, i am using two textfield and
I'm very new to iPhone development and I'm making an application where I have
New to iPhone development, but I've been given a big project as a first
I am new to iphone development and making an application which chooses an image
i am new to iphone development.. i am making an application in which table
I am very new to iPhone development. I downloaded the iPhoneHTTPServer application from bellow
I'm pretty new to iPhone development but I'm close to releasing my first app
Very new to Iphone development here, I have a project which is successfully building
I'm quite new to iPhone development and I'm building my first app :) In

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.