Hi,
I've been trying desperately to find how to do this.
I have a series of products stored in a dictionary (which comes from a plist), each product as a "Price" key, and a number as its value. Using NSNumberFormatter, I'm able to convert to currency successfully.
How do I add them up?
I have a table view, which lists all the products and their prices in the dictionary, formatted as currency. Outside of the table view but in the same class is a UILabel that I want to display the total price of all the products.
Here is the relevant code under cellForRowAtIndexPath:
There are two problems: how I add them and how I display the final tally? For the final tally, I need to set the UILabel in ViewDidLoad, but that is called before the above is called. How do I add all the prices, then display that in the UILabel?
Any help would be amazing.
Thanks!!
I've been trying desperately to find how to do this.
I have a series of products stored in a dictionary (which comes from a plist), each product as a "Price" key, and a number as its value. Using NSNumberFormatter, I'm able to convert to currency successfully.
How do I add them up?
I have a table view, which lists all the products and their prices in the dictionary, formatted as currency. Outside of the table view but in the same class is a UILabel that I want to display the total price of all the products.
Here is the relevant code under cellForRowAtIndexPath:
Code:
NSNumberFormatter *priceFormatter = [[NSNumberFormatter alloc] init];
[priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *price = [priceFormatter stringFromNumber:[[orderSummaryDictionary objectForKey:[self.orderSummaryArray objectAtIndex:row]] objectForKey:@"Price"]];
[priceFormatter release];
cell.productName.text = [self.orderSummaryArray objectAtIndex:row];
cell.productDescription.text = [[orderSummaryDictionary objectForKey:[self.orderSummaryArray objectAtIndex:row]] objectForKey:@"Description"];
cell.productPrice.text = price;
cell.productImage.image = [UIImage imageNamed:imageFile];
cell.productImage.layer.masksToBounds = YES;
cell.productImage.layer.cornerRadius = 5.0;
There are two problems: how I add them and how I display the final tally? For the final tally, I need to set the UILabel in ViewDidLoad, but that is called before the above is called. How do I add all the prices, then display that in the UILabel?
Any help would be amazing.
Thanks!!