[英]Program received signal: “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”. 我有一个字符串变量存储日期选择器的日期,但是当我在其他函数中使用它的值时,我收到错误,如程序接收信号:“EXC_BAD_ACCESS”。 Note: variable is globally defined.
注意:变量是全局定义的。
code : 代码:
- (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.
这是最可能的原因。
Edit: 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/
请查看http://www.markj.net/iphone-memory-debug-nszombie/
Whenever there is a crash, post the backtrace. 每当发生崩溃时,发布回溯。
Before you do, use "build and analyze" and fix any problems it identifies. 在此之前,请使用“构建和分析”并修复它识别的任何问题。
After doing that, if it still crashes, then do a pass with Zombie detection on and see if you are over-releasing something (which is likely, that code has an obvious over-release problem as is). 在这样做之后,如果它仍然崩溃,那么在Zombie检测上进行一次传递,看看你是否过度释放了某些东西(很可能,这个代码有明显的过度释放问题)。
If it is still crashing, then we'll need to see more code.... 如果它仍然崩溃,那么我们需要看到更多代码....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.