Ios 如何在DateWithTimeIntervalsIn1970中使用文本字段文本?
我在xcode中使用此代码作为倒计时的一部分:Ios 如何在DateWithTimeIntervalsIn1970中使用文本字段文本?,ios,objective-c,xcode,uitextfield,nsdate,Ios,Objective C,Xcode,Uitextfield,Nsdate,我在xcode中使用此代码作为倒计时的一部分: destinationDate = [NSDate dateWithTimeIntervalSince1970:1392375102]; 我还有一个文本字段,用户可以在其中输入DateWithTimeIntervals所需的历元时间戳 我将文本字段存储为: - (void)viewDidLoad { [textf7 setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"
destinationDate = [NSDate dateWithTimeIntervalSince1970:1392375102];
我还有一个文本字段,用户可以在其中输入DateWithTimeIntervals所需的历元时间戳
我将文本字段存储为:
- (void)viewDidLoad {
[textf7 setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey7"]];
[label7 setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"stringKey7"]];
}
及
问题是:
如何获取用户输入的值,并将其放置在第一个代码序列中的“1392375102”处
多谢各位 你的问题不清楚。假设要将
textf7.text
从NSString
转换为NSTimeInterval
,可以执行以下操作:
destinationDate = [NSDate dateWithTimeIntervalSince1970:[myString7 intValue];
destinationDate = [NSDate dateWithTimeIntervalSince1970:[textf7.text doubleValue]];
谢谢对不起,我是个笨蛋。。。但仍然不起作用。测试时生成崩溃,它会使倒计时混乱,显示负值…使用调试器验证
textf7.text
的内容。问题可能出在其他地方,但您只粘贴了一行代码来显示日期。
destinationDate = [NSDate dateWithTimeIntervalSince1970:[textf7.text doubleValue]];