将 NSDate 传递给指针时的 EXC_BAD_ACCESS
我在注释行中收到此错误。 datachoice是UserData的一个对象,它是外部的,但我导入了它。 我也在 .h 中保留了日期保存,我不知道加入是什么,可能是没有发布的东西???
.h.m
#import <UIKit/UIKit.h>
@interface DateViewController : UIViewController
@property (strong, retain) IBOutlet UIDatePicker *datepick;
@property (strong, retain) IBOutlet NSDate *datesave;
- (IBAction)okDatebutton:(id)sender;
@end
-(IBAction)okDatebutton:(id)sender {
datesave = [datepick date];
datechoice->date = datesave; //<-----------------here is the EXC_BAD_ACCESS
}
@end
I'm getting this error in the commented line.
datachoice is an Object of UserData, which is external but I imported it.
I retained datesave in the .h as well I don't know what Is join on, something with out release probably???
.h
#import <UIKit/UIKit.h>
@interface DateViewController : UIViewController
@property (strong, retain) IBOutlet UIDatePicker *datepick;
@property (strong, retain) IBOutlet NSDate *datesave;
- (IBAction)okDatebutton:(id)sender;
@end
.m
-(IBAction)okDatebutton:(id)sender {
datesave = [datepick date];
datechoice->date = datesave; //<-----------------here is the EXC_BAD_ACCESS
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
切勿 (*) 对对象使用
->
运算符。您的意思是:(*) 此规则有一个模糊的例外,可以要求它,但它不适用于 iOS,仅适用于 Mac。
Never(*) use the
->
operator for objects. You meant:(*) There's an obscure exception to this rule where it can be required, but it doesn't apply to iOS, only Mac.
你用的是ARC吗?我认为您的属性定义看起来错误。
如果我没记错的话,
strong
仅在使用 ARC 时有效,而retain
仅在不使用 ARC 时有效。我很惊讶它能让你编译,如果这是问题的话。Are you using ARC? I think your property definitions look wrong.
If I recall correctly,
strong
is only valid with ARC, andretain
is only valid without ARC. I'm surprised it lets you compile if that's the problem though.