小编use*_*343的帖子

NSTimer的准确性

我正在尝试使用NSTimer创建一个Stop-watch样式计时器,每0.1秒递增一次,但有时它似乎运行得太快了.

这就是我做到的方式:

Timer =[NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector(updateTimeLabel) userInfo:nil repeats: YES];
Run Code Online (Sandbox Code Playgroud)

然后:

-(void)updateTimeLabel
{
    maxTime=maxTime+0.1;
    timerLabel.text =[NSString stringWithFormat:@"%.1f Seconds",maxTime];
}
Run Code Online (Sandbox Code Playgroud)

这将在Label中显示计时器的值,稍后我可以将maxTime用作Timer停止的时间...

问题是它运行非常不准确.

有没有一种方法可以确保NSTimer严格每0.1秒严格发射一次?我知道NSTimer不准确,我要求进行调整以使其准确.

谢谢

objective-c nstimer

6
推荐指数
3
解决办法
3780
查看次数

从UIAlertView获取文本

似乎有东西丢失,但下面的代码正在生成nil的两个值titletitle1(即使它正确启动正确的警报类型,并不表示任何警告或错误).这个实现的问题可能是什么UIAlertView

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"High Score" message:(NSString *)scoreMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.alertViewStyle= UIAlertViewStylePlainTextInput;
UITextField *title1 = [alert textFieldAtIndex:0];
[alert show];
title1= [alert textFieldAtIndex:0];
NSString *title = title1.text;
NSLog(@"The name is %@",title);
NSLog(@"Using the Textfield: %@",[[alert textFieldAtIndex:0] text]);
Run Code Online (Sandbox Code Playgroud)

objective-c uialertview ios

3
推荐指数
2
解决办法
5472
查看次数

标签 统计

objective-c ×2

ios ×1

nstimer ×1

uialertview ×1