i have 2 collectionview. 1 main , second sub items when click both collectionview data added in tableview.
my requirement when click on first collectionview added in cart , tableviewcell should display original price retrieve web service.
now when click on second collectionview should added tableview when click have display price 0. add tableview using did select method of collectionview:
func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) { let dictsub = arr[indexpath.row] as! [string : anyobject] //to insert product top of tableview arrtable(dictsub, atindex: 0) self.tbl.reloaddata() } at cellforrowatindexpath method checking ismainproduct equals 1 or zero
code :
if isfrommain == "1" { let price = nsstring(string: pprice1).floatvalue let total = 1 * price cell.lbl.text = string(format: "%.2f", total) } else { let price = 0.00 let total = 1 * price cell.lbl.text = string(format: "%.2f", total) } when 1 add original price when not main product display zero.
issue is:
first when click on main collection view original price displayed when clicked on sub items price of main product changes zero.
i want prevent data overwriting.
in didselectitematindexpathyou adding dictionaryto array, can use dictionary differentiate coming main collectionview or not instead of setting instance value of isfrommain 1.
func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) { var dictsub = arr[indexpath.row] as! [string : anyobject] if collectionview == maincollectionview { dictsub["isfrommain"] = "1" } else { dictsub["isfrommain"] = "0" } arrtable(dictsub, atindex: 0) self.tbl.reloaddata() } now use key in cellforrowatindexpath check coming main collectionview or second one.
let dic = arrtable[indexpath.row] as! [string : anyobject] let isfrommain = dic["isfrommain"] as! string if isfrommain == "1" { let price = nsstring(string: pprice1).floatvalue let total = 1 * price cell.lbl.text = string(format: "%.2f", total) } else { let price = 0.00 let total = 1 * price cell.lbl.text = string(format: "%.2f", total) }
Comments
Post a Comment