double variable not able to hold onto values
i have a double variable in my application and i update some values to it in viewDidLoad method and want to use it later in one of the delegate method of tableview but the variable is not able to retain the value. I am declaring it as follows:
double subTtl;
@property(nonatomic,assign) double subTtl;
mycode for viewdidLoad
subTtl = 0;
for (int i = 0; i<[pizzaAppDel.arrOrders count]; i++) {
[pizzaAppDel.arrOrderDetails addObject:@"1"];
subTtl = subTtl + [[(NSDictionary*)[pizzaAppDel.arrOrders objectAtIndex:i] objectForKey:@"price"] doubleValue];
}
NSLog(@"%@",[NSString stringWithFormat:@"%.2f",subTtl]);
This is how i m using it in my tableview delegate method:
lblTtlPrice.text = [@"Subto开发者_运维问答tal: $" stringByAppendingString:[NSString stringWithFormat:@"%.2f",subTtl]];
i am synthesising it in .m file and saving some values, i can see the values inside the variable but when i try to use it later i get nothing from it, variable returns empty.
If subTtl is an instance variable of your view controller and you want to access it from another instance (say, your app delegate), you will need a reference to the view controller. You can then access subTtl as a property:
lblTtlPrice.text = [@"Subtotal: $" stringByAppendingString:[NSString stringWithFormat:@"%.2f",viewController.subTtl]];
精彩评论