使用 [NSDecimalNumber stringValue] 发生硬崩溃
当我尝试访问 NSDecimalNumber amount_before_current_year 的任何属性时,我的应用程序崩溃:
[amount_before_current_year stringValue]
Program received signal: “EXC_BAD_ACCESS”.
该对象是 NSDecimalNumber,如所附图像所示。
我在 viewDidLoad 中创建了它,它存在于头文件中:
.h
...
NSDecimalNumber *amount_before_current_year;
...
@property (nonatomic, retain) NSDecimalNumber *amount_before_current_year;
...
也在实现文件中:
@synthesize amount_before_current_year;
amount_before_current_year = [NSDecimalNumber decimalNumberWithString:@"100.00"];
在这里我再次调用它:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *test = [amount_before_current_year stringValue]; // HARD CRASH !!!
所以,我不知道现在该怎么办,我已经花了几个小时来处理这个...... ?
有什么想法吗
谢谢, 河
My app crash when I try to access any property of my NSDecimalNumber amount_before_current_year:
[amount_before_current_year stringValue]
Program received signal: “EXC_BAD_ACCESS”.
The object is a NSDecimalNumber as shown in the image attached.
I created it in the viewDidLoad, it exists in the header file:
.h
...
NSDecimalNumber *amount_before_current_year;
...
@property (nonatomic, retain) NSDecimalNumber *amount_before_current_year;
...
also in the implementation file:
@synthesize amount_before_current_year;
amount_before_current_year = [NSDecimalNumber decimalNumberWithString:@"100.00"];
here I call it again:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *test = [amount_before_current_year stringValue]; // HARD CRASH !!!
so, I don't know what to do now, I've spent some hours with this .....
any ideas ??????
thanks,
r.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在分配给它时保留 amount_before_current_year ,或者使用点符号分配给它:
由于您使用保留属性声明了该属性,因此合成的设置器将自动发送一条保留消息,并释放任何先前的值。我推荐这种方法。
You need to either retain amount_before_current_year when you assign to it, or use dot notation to assign to it:
Since you declared the property with the retain attribute, the synthesized setter will automatically send a retain message, as well as releasing any previous value. I recommend this approach.