here is the image i had designed
here is the code for UITableviewCell
and in this I had placed the stepper action method to trigger but unable to update the price label when I tap on stepper
can anyone help me?
class productTableViewCell: UITableViewCell {
@IBOutlet var stepper: UIStepper!
@IBOutlet var imageview: UIImageView!
@IBOutlet var nameLabel: UILabel!
@IBOutlet var priceLabel: UILabel!
@IBOutlet var quantityTextField: UITextField!
var pricearr = [String]()
var price : String = ""
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
@IBAction func changeCart(_ sender: Any) {
let value = Int(stepper.value)
quantityTextField.text = String(value)
}
}
Here is the code for UITableViewCell
and in this I had placed the stepper action method to trigger but unable to update the price label when I tap on the stepper can anyone help me?
@IBOutlet var tableDetails: UITableView!
var productsArray = [String]()
var nameArray = [String]()
var priceArray = [String]()
let urlstring = "http://www.json-generator.com/api/json/get/ceghMiWudK?indent=2"
var price = [String]()
var sum = 0
override func viewDidLoad() {
super.viewDidLoad()
self.downloadJsonWithURL()
tableDetails.delegate = self
tableDetails.dataSource = self
tableDetails.alwaysBounceVertical = false
// Do any additional setup after loading the view.
}
func downloadJsonWithURL() {
let url = NSURL(string: urlstring)
URLSession.shared.dataTask(with: (url as? URL)!, completionHandler: {(data, response, error) -> Void in
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary {
print(jsonObj!.value(forKey: "Detail"))
if let detailsArray = jsonObj!.value(forKey: "Detail") as? NSArray {
for item in detailsArray {
if let detailDict = item as? NSDictionary {
if let name = detailDict.value(forKey: "productName"){
self.nameArray.append(name as! String)
}
if let price = detailDict.value(forKey: "productPrice"){
self.priceArray.append(price as! String)
}
if let image = detailDict.value(forKey: "img"){
self.productsArray.append(image as! String)
}
}
}
}
OperationQueue.main.addOperation({
self.tableDetails.reloadData()
for item in self.priceArray{
let endIndex = item.index(item.endIndex, offsetBy: -5)
let truncated = item.substring(to: endIndex)
self.price.append(truncated)
}
print(self.price)
})
}
}).resume()
}
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 3
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
if (section == 0){
return productsArray.count
}else{
return 1
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! productTableViewCell
let arr = self.productsArray[indexPath.row]
let urls = NSURL(string: arr)
let data = NSData (contentsOf: urls! as URL)
cell.imageview.image = UIImage(data: data! as Data)
cell.nameLabel.text = nameArray[indexPath.row]
let x = priceArray[indexPath.row]
let array = String(x)
cell.priceLabel.text = array
cell.quantityTextField.text = "1"
cell.pricearr = [price[indexPath.row]]
return cell
}else if indexPath.section == 1{
let cell = tableView.dequeueReusableCell(withIdentifier: "couponcell", for: indexPath) as! CouponTableViewCell
return cell
}else {
let cell = tableView.dequeueReusableCell(withIdentifier: "checkout", for: indexPath) as! checkoutTableViewCell
return cell
}
}