Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a StopWatch in Iphone
    primarykey
    data
    text
    <p>I am trying to create a simple stopwatch. I referred to this website ( <a href="http://www.apptite.be/tutorial_ios_stopwatch.php" rel="nofollow">http://www.apptite.be/tutorial_ios_stopwatch.php</a>) to do this app. When I click the start button, I get -596:-31:-23:-648 and the stopwatch does not run.</p> <p>The code looks like:</p> <p>ViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ViewController : UIViewController{ UILabel *lbl; NSTimer *stopTimer; NSDate *startDate; } @property (strong,nonatomic) IBOutlet UILabel *lbl; -(IBAction)startPressed:(id)sender; -(IBAction)stopPressed:(id)sender; -(void)updateTimer; @end </code></pre> <p>ViewController.m</p> <pre><code>#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize lbl; - (void)viewDidLoad { [super viewDidLoad]; lbl.text = @"00.00.00.000"; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)startPressed:(id)sender{ if (stopTimer == nil) { stopTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES]; } } -(IBAction)stopPressed:(id)sender{ [stopTimer invalidate]; stopTimer = nil; //[self updateTimer]; } -(void)updateTimer{ NSDate *currentDate = [NSDate date]; NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate]; NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm:ss.SSS"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]]; NSString *timeString=[dateFormatter stringFromDate:timerDate]; lbl.text = timeString; } @end </code></pre> <p>Need some guidance on solving the error. Not sure where the error is. Appreciate any help...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload