Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 制作一个在Objective-C中排名的计时器_Ios_Objective C_Milliseconds - Fatal编程技术网

Ios 制作一个在Objective-C中排名的计时器

Ios 制作一个在Objective-C中排名的计时器,ios,objective-c,milliseconds,Ios,Objective C,Milliseconds,我想在我的应用程序中排名,你可以看到谁跑得最快。 我试图将时间转换成毫秒,但效果不好 这是我目前的代码 #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize watch,start,reset; - (void)viewDidLoad { [super viewDidLoad]; running = NO; count

我想在我的应用程序中排名,你可以看到谁跑得最快。 我试图将时间转换成毫秒,但效果不好

这是我目前的代码

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize watch,start,reset;


- (void)viewDidLoad {
    [super viewDidLoad];




running = NO;
count = 0;
watch.text = @"00:00.00";

start.layer.cornerRadius = 45;
reset.layer.cornerRadius = 45;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}







- (IBAction)startpressed:(id)sender {

    if (running == NO) {
        running = YES;
        [start setTitle:@"STOPP" forState:UIControlStateNormal];

       NSDate *watch = [NSDate dateWithTimeIntervalSince1970:(1273636800 / 1000.0)];

        if (myTimer == nil) {

            myTimer = [NSTimer scheduledTimerWithTimeInterval:0.0055
                                                       target:self
                                                       selector:@selector(updateTimer)
                                                       userInfo: nil
                                                       repeats:YES];

        }


    } else {

        running = NO;
        [myTimer invalidate];
        myTimer = nil;
        [start setTitle:@"START" forState:UIControlStateNormal];

    }

}

- (IBAction)resetpressed:(id)sender {
    running =NO;
    [myTimer invalidate];
    myTimer =nil;
    [start setTitle:@"START" forState:UIControlStateNormal];
    count = 0;
    watch.text = @"00:00.00";


}


- (void)updateTimer {
    count++;

    int min = floor(count/100/60);
    int sec = floor(count/100);
    int mSec = count % 100;


    if (sec >= 60) {
        sec = sec % 60;

    }

    watch.text = [NSString stringWithFormat:@"%02d:%02d.%02d", min,sec,mSec];  
}
@end
这是我的ViewController.h代码:

#import <UIKit/UIKit.h>



@interface ViewController : UIViewController
{
    NSTimer *myTimer;
    BOOL running;
    int count;
    double methodStart;

}

@property (weak, nonatomic) IBOutlet UILabel *watch;
@property (weak, nonatomic) IBOutlet UIButton *start;
@property (weak, nonatomic) IBOutlet UIButton *reset;
@property (weak, nonatomic) IBOutlet UILabel *eins;
@property (weak, nonatomic) IBOutlet UILabel *zwei;
@property (weak, nonatomic) IBOutlet UILabel *drei;


- (IBAction)startpressed:(id)sender;
- (IBAction)resetpressed:(id)sender;

- (void) updateTimer;

@end
#导入
@界面ViewController:UIViewController
{
NSTimer*myTimer;
布尔跑;
整数计数;
双方法启动;
}
@属性(弱,非原子)IBUILabel*手表;
@属性(弱,非原子)IBUIButton*启动;
@属性(弱,非原子)按钮*重置;
@属性(弱、非原子)IBUILabel*EIN;
@性质(弱,非原子)IBUILabel*zwei;
@性质(弱,非原子)IBUILabel*drei;
-(iAction)startpressed:(id)发送方;
-(iAction)重置按下:(id)发送方;
-(void)updateTimer;
@结束

在类接口/扩展中创建用于保存搭接历史的数组,并对其进行初始化

self.lapHistory = [@[] mutableCopy];
当圈重设/停止时,捕获并排序每圈时间

- (IBAction)resetpressed:(id)sender {
   [self.lapHistory addObject:@(count)];
   self.lapHistory = [self.lapHistory sortedArrayUsingSelector: @selector(compare:)];
}
显示从历史中排序的排名

-(void)displayRanking{
  NSMutableString *rankingResult = [[NSMutableString alloc] init];
    for (NSNumber *lap in self.lapHistory) {
        [rankingResult appendString:[NSString stringWithFormat:@"%ld\n",[lap integerValue]]];
    }
  NSLog(@"Ranking result is %@", rankingResult);
}

面临的问题是什么?如果你想在你的应用程序中显示前三名,制作一个NSMutableArray并在每个停止计时器中向可变数组添加项目(时间圈)。然后在对数组排序后显示第一条、第二条和第三条记录。就这些。你能给我密码吗?这样我就可以把它复制到我的密码里了?