"EXC_BAD_ACCESS" in Xcode
while run iphone simulation, I show the error for "EXC_BAD_ACCESS" in Xcode
code is below :
Test.h
@interface Test : UIViewController
{
NSNumber *nWieght;
}
@property (nonatomic,retain) NSNumber *nWieght;
end
Test.m
@implementation Test
@synthesize nWieght;
- (voi开发者_开发技巧d)viewDidLoad
{
...
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
**NSLog(@"integer Number is :%@", iWeight); // error occur**
}
If i click the Button of UIAlertView, Xcode occur "EXC_BAD_ACCESS" error at that code
I don't know why that code occur error. help me.
You really left out the essentials here (the actual assignment) and you are using iWeight instead of nWeight (typo i'm sure) in your example. Just make sure when you assign the NSNumber
you actually assign it an NSNumber
object not a literal (ex. nWeight = 5). and also make sure you use the property. self.nWeight = [NSNumber numberWithInt:5];
I assume you mean nWieght on that NSLog line -- if not update with more code.
What has happened to nWieght in its lifetime? Does it have a value -- was that value released and dealloced?
The easiest way to tell is to turn on Zombies with the the Zombies instrument. This will set each object to not deallocate when it is fully released, and turn it into a zombie object instead. If you try to send a message to a zombie, it will complain loudly in the Console, and you get a much better indication of what you did wrong.
There are many other ways to cause EXC_BAD_ACCESS, which I documented here:
http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html
精彩评论