ios - Perform addition of values from each cell of tableview -
i working on shopping app add items in cart. have show sub total amount need perform addition of price of each item in table.
how can pick values each cell , add them?
below code tableview:
#pragma mark - table view data source - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [cartlist count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsdictionary *celldata = [[[cartlist objectatindex:indexpath.row] valueforkey:@"addtocartproductimagemodel"] firstobject]; nsstring *image=[celldata valueforkey:@"productimg"]; nsstring *urlstring = [nsstring stringwithformat:@"http://dealnxt.com/areas/user/productimage/%@", image]; nsurl *url = [nsurl urlwithstring:urlstring]; nsdata *data = [nsdata datawithcontentsofurl:url]; nsstring *celldata = [[cartlist objectatindex:indexpath.row] valueforkey:@"shortdescription"]; static nsstring *simpletableidentifier = @"cell"; carttableviewcell *cell = (carttableviewcell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier forindexpath: indexpath]; cell.proimg.image=[uiimage imagewithdata:data]; cell.prlbl.linebreakmode = nslinebreakbywordwrapping; cell.prlbl.numberoflines = 0; cell.prlbl.text=celldata; cell.prprice.text=[nsstring stringwithformat: @"₹%@",[[cartlist objectatindex:indexpath.row] valueforkey:@"price"]]; cell.quantity.text=[nsstring stringwithformat:@"%@",[[cartlist objectatindex:indexpath.row] valueforkey:@"quantity"]]; nsstring *string =[nsstring stringwithformat: @"%@",[[cartlist objectatindex:indexpath.row] valueforkey:@"price"]]; int value = [string intvalue]; (int i=0; i<=[cartlist count]; i++) { int total=0; total=+value; nslog(@"total:%d",total); } return cell; }
where prprice need add.
// write code somewhere fill cartlist variable value. float tot; (int = 0; < [cartlist count]; i++) { tot = tot + [[[cartlist objectatindex:i] valueforkey:@"price"] floatvalue]; // stuff... } nslog("total cost : ₹ %.2f",tot);
Comments
Post a Comment