【发布时间】:2011-06-25 03:00:22
【问题描述】:
为什么下面的代码会导致我的代码崩溃?
NSTimeInterval timeLeft = [NSDate timeIntervalSinceDate: [[NSUserDefaults 标准用户默认值] objectForKey:@"lastDate"]] [[[定时器用户信息] objectForKey:@"theLabel"] text:[NSString stringWithFormat:@"Time Remaining: %d", waitTime]]; //设置标签文字
我可以肯定变量没有问题。 userInfo 是通过 NSTimer 传入的字典。
谢谢!
【问题讨论】:
-
请格式化您的代码。这几乎是不可读的,而且您缺少分号和括号。
-
您还缺少崩溃日志、设置计时器的代码以及有关如何存储各种对象引用的任何信息;实例变量?全球人?本地人?
-
这可能是你想要做的(假设所有变量都存在并且按预期设置):
[[timer userInfo] setValue:[NSString stringWithFormat:@"Time Remaining: %d", waitTime] forKey:@"theLabel"];
标签: iphone objective-c nsdate