I had implemented a set of images from url and displaying it on collection view and table view and deployed in the iphone 5 device after loading app the images page was not scrolling fast and taking more time delay how to avoid this can anyone help me ?
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "productsCell", for: indexPath) as! productsCell
let arr = imageArray[indexPath.row]
let urls = NSURL(string: arr)
let data = NSData (contentsOf: urls! as URL) //make sure your image in this url does exist, otherwise unwrap in a if let check
cell.productImage.image = UIImage(data: data! as Data)
cell.productName.lineBreakMode = NSLineBreakMode.byWordWrapping
cell.productName.numberOfLines = 2
cell.productName.text = self.productName[indexPath.row]
cell.productPrice.text = self.productprice[indexPath.row]
cell.buynowButton .addTarget(self, action: #selector(buyNowButton(_:)), for:UIControlEvents.touchUpInside)
cell.cartButton .addTarget(self, action: #selector(cartButton(_:)), for:UIControlEvents.touchUpInside)
return cell
}