将 NSDate 传递给指针时的 EXC_BAD_ACCESS

发布于 2025-01-07 17:01:55 字数 572 浏览 4 评论 0原文

我在注释行中收到此错误。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小情绪 2025-01-14 17:01:55

切勿 (*) 对对象使用 -> 运算符。您的意思是:

self.datechoice.date = datesave;

(*) 此规则有一个模糊的例外,可以要求它,但它不适用于 iOS,仅适用于 Mac。

Never(*) use the -> operator for objects. You meant:

self.datechoice.date = datesave;

(*) There's an obscure exception to this rule where it can be required, but it doesn't apply to iOS, only Mac.

污味仙女 2025-01-14 17:01:55

你用的是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, and retain is only valid without ARC. I'm surprised it lets you compile if that's the problem though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文