I created my UIView class showing an internal activity indicator. This view informs you that at that time the application is performing an operation.
I'm trying to apply this UIView also login in my app but I have a problem ...
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 ...
The custom UIView should disappear as soon as the new view controller is presented ...
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 ..
Someone can 'help me in this?
if my understanding correct you want to set a timer then you want show execution time in a different view controller?
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.
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 file
//
// 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
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);