相关疑难解决方法(0)

NStimer在iOS中无法正常工作

我正在使用以下代码显示时间...我在viewController中有滚动视图...这里我显示的时间从00:00.00开始(mm:ss:SS)(分钟:秒:毫秒)并且目标是递增毫秒,秒基于毫秒,基于秒的分钟...但我想显示从75:00.00(mm:ss:SS)开始的时间,我想将毫秒,秒和分钟减少到00:00.00(mm:ss) .SS)......我怎么能......?

我在以下链接中已经在SO中询问过这个问题.NSTimer以秒/毫秒减少时间

我按照那段代码时间不计算(在后台也是)当我拖动并按住滚动视图而不释放鼠标点击...帮我修改下面的代码...

enter code here
@interface ViewController : UIViewController
{
    IBOutlet UILabel *time;
    NSTimer *stopWatchTimer;
    NSDate *startDate;
    NSTimeInterval secondsAlreadyRun;
}

- (void)reset:(id)sender;
- (void)onStartPressed:(id)sender; 
- (void)onStopPressed:(id)sender;


enter code here
-(void)showActivity:(NSTimer *)tim 
{
    NSDate *currentDate = [NSDate date];

    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    // Add the saved interval
    timeInterval += secondsAlreadyRun;
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    static NSDateFormatter * dateFormatter = nil;
    if( !dateFormatter ){
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"mm:ss.SS"];
        [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
    }
    NSString *timeString=[dateFormatter …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nstimer ios5 xcode4.2

4
推荐指数
2
解决办法
3931
查看次数

使用NSTimer的秒表错误地包括显示中的暂停时间

这是我的iPhone秒表代码.它按预期工作,并在单击按钮时停止并恢复.

然而,当我点击"停止"时,计时器将不会在后台停止运行,当我点击"开始"恢复它时,它将更新时间并跳到当前的位置,而不是从停止的时间恢复.

我怎么能阻止NSTimer?是什么导致这种情况发生?

@implementation FirstViewController;
@synthesize stopWatchLabel;

NSDate *startDate;
NSTimer *stopWatchTimer;
int touchCount;


-(void)showActivity {

    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"mm:ss.SS"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
    NSString *timeString=[dateFormatter stringFromDate:timerDate];
    stopWatchLabel.text = timeString;
    [dateFormatter release];
}

- (IBAction)onStartPressed:(id)sender {

    stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1/10 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];

    touchCount += 1;
    if (touchCount > 1)
    {
        [stopWatchTimer fire];
    }
    else 
    {
        startDate = [[NSDate date]retain]; …
Run Code Online (Sandbox Code Playgroud)

time cocoa-touch objective-c nstimer ios

3
推荐指数
1
解决办法
5583
查看次数

标签 统计

nstimer ×2

objective-c ×2

cocoa-touch ×1

ios ×1

ios5 ×1

iphone ×1

time ×1

xcode4.2 ×1