程序接收信号:"EXC_BAD_ACCESS" [英] Program received signal: “EXC_BAD_ACCESS”
问题描述
我有一个字符串变量,用于存储日期选择器中的日期,但是当我在其他函数中使用它的值时,出现错误,例如程序收到的信号:"EXC_BAD_ACCESS".注意:变量是全局定义的.
I have a string variable which stores date from date picker but when I use its value in other function I am getting error like Program received signal: "EXC_BAD_ACCESS". Note: variable is globally defined.
代码:
- (void) changedDate: (UIDatePicker *) picker
{
if (appDelegate.dateint == 8)
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd MMM, yyyy"];
datestr=[dateFormatter stringFromDate:[dptpicker date]];
NSLog(@"date:%@",datestr);
}
else if(appDelegate.dateint == 9)
{ NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd MMM, yyyy"];
datestr1=[dateFormatter stringFromDate:[dptpicker date]] ;
NSLog(@"date1:%@",datestr1);
}
}
推荐答案
您必须保留该字符串.这是最可能的原因.
You have to retain that string. This is the most likely reason.
它崩溃的唯一原因是指针错误.错误的指针=过度释放对象.只需在启用了僵尸的情况下运行您的应用程序,您就会看到执行此操作的位置.选中此 http://www.markj.net/iphone-memory-debug-nszombie/
The only reason why it is crashing is the bad pointer. The bad pointer = over-releasing the object. Just run your app with zombies enabled and you'll see the place where you're doing that. Check this http://www.markj.net/iphone-memory-debug-nszombie/
这篇关于程序接收信号:"EXC_BAD_ACCESS"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!