私は二重に呼ばれる時間があります。double を別のクラスのメソッドに渡すことができる理由を判断できませんが、同じメソッドが存在するクラスからその double を要求することはできません。
私のヘッダーファイルは次のようになります。
@property (nonatomic) double time;
私の実装は次のようになります。
@implementation MainVewController
@synthesize time;
- (void) viewDidLoad
{
startTime = NSDate.date;
}
- (double) returnTime {
NSLog (@"time is disappearing?? %f", time);
return time;
}
- (double) logTime {
NSLog (@"for some reason, this one is working and returns a value %f", time);
return time;
}
私の他のクラスは私のダブルを求めています:
@synthesize mainViewController = _mainViewController ;
- (MainViewController *)mainViewController {
if (!_mainViewController) _mainViewController = [[MainViewController alloc] init];
return _mainViewController;
}
- (BOOL)getTime {
double timeGotten = [self.mainViewController returnTime];
// why does this return 0?
return TRUE;
}
時間変数は、MainVewController 内で継続的に更新されています。
time = [[NSDate date] timeIntervalSinceDate: startTime];