计算一个视图控制器和另一个视图控制器切换之间的时间 [英] Calculate the time between the switches of a View Controller and another View Controller

查看:49
本文介绍了计算一个视图控制器和另一个视图控制器切换之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了显示内部活动指示器的 UIView 类.此视图通知您当时应用程序正在执行操作.

I created my UIView class showing an internal activity indicator. This view informs you that at that time the application is performing an operation.

我正在尝试在我的应用程序中应用此 UIView 也登录,但我遇到了问题...

I'm trying to apply this UIView also login in my app but I have a problem ...

我希望能够计算从用户输入用户名和密码到访问应用主屏幕的时间.在那一刻,我会看到我的 UIView 通知你,在那一刻他正在做一个操作......

I would like to be able to calculate the time that the app takes from the moment the user enters his username and password, up to the moment when access to the home screen of the app. In that moment of time I would see my UIView which informs you that at that moment he is making an operation ...

一旦出现新的视图控制器,自定义 UIView 就会消失......

The custom UIView should disappear as soon as the new view controller is presented ...

为此,我想到了一个 NSTimer,也许在我的 UIView 类中有一个特定的方法,但我不知道如何设置计时器以返回视图控制器和另一个切换之间的正确时间..

To do this I was thinking of a NSTimer, perhaps with a particular method within my UIView class but I would not know how to set the timer to return the correct time between the switch of a View Controller and another ..

有人可以帮助我吗?

推荐答案

如果我的理解正确,您想设置一个计时器,那么您想在不同的视图控制器中显示执行时间?

if my understanding correct you want to set a timer then you want show execution time in a different view controller?

我会用一个 nsdate 对象创建一个单例,我会将该 nsdate 对象设置为当前时间,然后在用户完成他正在做的任何事情后,我将创建另一个 nsdate 对象并比较过去的时间.

I would create a singleton with a nsdate object, I would set that nsdate object to current time then after user done whatever he is doing, I will create another nsdate object and compare the time passed.

所以创建一个objective-c类,我创建了一个叫做showtimer的东西.h 文件

So create an objective-c class, I created somethinf called showtimer .h file

//
//  ShowTimer.h
//  app
//

#import <Foundation/Foundation.h>

@interface ShowTimer : NSObject
{
    NSDate *passed;
}

@property (nonatomic, retain) NSDate *passed;
+ (id)sharedManager;
@end

.m 文件

//
//  ShowTimer.m
//  app
//

#import "ShowTimer.h"

@implementation ShowTimer
@synthesize passed;

#pragma mark Singleton Methods

+ (id)sharedManager {
    static ShowTimer *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

- (id)init {
    if (self = [super init]) {

    }
    return self;
}

- (void)dealloc {
    // Should never be called, but just here for clarity really.
}
@end

在你的视图控制器中导入 #import "ShowTimer.h"然后在任何地方初始化计时器

in your view controllers import #import "ShowTimer.h" then initialize the timer wherever you want

ShowTimer *timer=[ShowTimer sharedManager];
    timer.passed=[NSDate date];

然后在您喜欢的任何地方在另一个视图/视图控制器方法中调用它

then call it in another view/viewcontroller methof wherever you like

ShowTimer *timer=[ShowTimer sharedManager];
    NSDate *methodFinish = [NSDate date];
    NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:timer.passed];
    NSLog(@"Execution Time: %f", executionTime);

这篇关于计算一个视图控制器和另一个视图控制器切换之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆