小编Luc*_*nts的帖子

在Iphone中创建一个StopWatch

我正在尝试创建一个简单的秒表.我提到这个网站(http://www.apptite.be/tutorial_ios_stopwatch.php)来做这个应用程序.当我点击开始按钮时,我得到-596:-31:-23:-648并且秒表不运行.

代码如下:

ViewController.h

#import <UIKit/UIKit.h>

@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
Run Code Online (Sandbox Code Playgroud)

ViewController.m

#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 …
Run Code Online (Sandbox Code Playgroud)

iphone nstimer ios

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

iphone ×1

nstimer ×1