Var 在 ViewDIdLoad 中可见,但在其他地方不可见
我正在编写一个 iPhone 应用程序,但出现了一个问题;我可以在 viewDidLoad 方法中使用 NSDate 变量,但不能在其他地方使用!怎样才能制作出来呢?如何解决?
这是我的重要几行:
@interface GraphNavController : UINavigationController {
IBOutlet UIImage *image;
CGPoint gestureStartPoint;
IBOutlet UISegmentedControl *segmentedControl;
NSDateComponents *dateComponents;
NSCalendar *gregorian;
@public
NSDate *date;
}
在实现代码中...
- (void)viewDidLoad {
[super viewDidLoad];
date = [[NSDate alloc] init];
// Set the GMT @ 2
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setTimeZone:[NSTimeZone timeZoneWithName:@"GMT+2"]];
dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:11];
[dateComponents setMonth:11];// tests ^^
date = [gregorian dateByAddingComponents:dateComponents toDate:date options:0];
NSLog(@"--> Date : %@ - DComponents's : %d-%d-%d - gregorian : %@",date, [dateComponents day], [dateComponents month], [dateComponents year], [gregorian calendarIdentifier]); // is running here completely well
}
并且日期变量隐藏在此类的任何其他方法中...
我已经尝试将该变量放入 @public、@private、@package、..但什么都没有运行。
该应用程序正在杀死没有给出任何问题描述!我只需要将日期日志放在 viewOnLoad 以外的任何地方,就会出现崩溃......
I'm programming one iphone app, and there is a problem; I can use a NSDate variable in the viewDidLoad method but not somewhere else! How can it be made? how can it be resolved?
here's my important lines:
@interface GraphNavController : UINavigationController {
IBOutlet UIImage *image;
CGPoint gestureStartPoint;
IBOutlet UISegmentedControl *segmentedControl;
NSDateComponents *dateComponents;
NSCalendar *gregorian;
@public
NSDate *date;
}
And in the implementation code...
- (void)viewDidLoad {
[super viewDidLoad];
date = [[NSDate alloc] init];
// Set the GMT @ 2
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setTimeZone:[NSTimeZone timeZoneWithName:@"GMT+2"]];
dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:11];
[dateComponents setMonth:11];// tests ^^
date = [gregorian dateByAddingComponents:dateComponents toDate:date options:0];
NSLog(@"--> Date : %@ - DComponents's : %d-%d-%d - gregorian : %@",date, [dateComponents day], [dateComponents month], [dateComponents year], [gregorian calendarIdentifier]); // is running here completely well
}
And the date variable is hidden in any other method of this class...
I already try to put that variable in @public, @private, @package, ... but nothing is running.
The app is killing without give any description of the problem! I just have to put a Log of the date anywhere else than in the viewOnLoad and the crash appears...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dateByAddingComponents:toDate:options:
返回一个自动释放的对象。你应该保留它。如果您使用属性:那么您可以这样做:
dateByAddingComponents:toDate:options:
returns an autoreleased object. You should retain it. If you use a property:then you can do this: