设置整数时,为什么会发生EXC_BAD_ACCESS和SIGABRT? [英] Why did happen EXC_BAD_ACCESS and SIGABRT when set integer?
本文介绍了设置整数时,为什么会发生EXC_BAD_ACCESS和SIGABRT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了代码.
我想使用nsuserdefault保存整数.
但是此代码发生在EXC_BAD_ACCESS和SIGABRT.
I wrote code.
I want to save integer using nsuserdefault.
But this code happen EXC_BAD_ACCESS and SIGABRT.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
[self desave:[newys integerValue] :[newms integerValue]];
...
}
...
- (void)desave:(NSInteger*)year :(NSInteger*)month//←EXC BAD ACCESS happened on this row.
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:year forKey:@"year"];//←SIGABRT happened on this row.
[defaults synchronize];
}
推荐答案
此问题是由用于NSInteger
参数的不必要的指针引起的.
The problem is caused by the needless pointers being used for the NSInteger
parameters.
更改:
- (void)desave:(NSInteger*)year :(NSInteger*)month
收件人:
- (void)desave:(NSInteger)year :(NSInteger)month
NSInteger
不是类类型.
您还应该为您的方法命名更好一些.现在,名称为desave::
.最好是:
You should also name your method a little better. Right now the name is desave::
. It would be better if it was:
- (void)desaveYear:(NSInteger*)year month:(NSInteger*)month
现在的名字是desaveYear:month:
.
现在您可以通过以下方式调用它:
And now you can call it with:
[self desaveYear:[newys integerValue] month:[newms integerValue]];
这篇关于设置整数时,为什么会发生EXC_BAD_ACCESS和SIGABRT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文