Everything was working fine till I added a new NSNUmber variable.
My .h file looks has this –
NSNumber *foodPriceTotal;
@property (assign, readwrite) NSNumber *foodPriceTotal;
and in my .m file I have –
@synthesize foodPriceTotal;
In my Initwithnibname method I do this –
foodPriceTotal = [[NSNumber alloc] init];
In my cellForRowAtIndexPath function I do this
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
CGFloat deliveryCharge = [prefs floatForKey:@"deliveryCharge"];
foodPriceTotal = [NSNumber numberWithFloat:([foodPriceTotal floatValue] + deliveryCharge)];
I get error EXEC_BAD_ACCESS(Code=1) when I scroll up and down –
The erring line is –
foodPriceTotal = [NSNumber numberWithFloat:([foodPriceTotal floatValue] + deliveryCharge)];
Any idea please?
As Till pointed out, your ownership qualifier (
assign) is not what you want here. In 99% withNSNumberyou wantcopyinstead.Then later, use the accessor method:
No reason to put that
NSNumber *foodPriceTotaldeclaration into your .h file at all, just delete that line.Regarding your
initmethod, you might want to rethink about your logic. What is a number without any value here? Probablynilis just as good and much clearer.