I use collectionView (inside tableView) for horizontal scrolling image and tableView for vertical scroll info.
If i scroll up or scroll down i get auto reset my page number, what can be the reason? But if i continue scrolling image i get current page number.
My code for display current page number:
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let indexPath = IndexPath(row: 0, section: 0)
if let cell = tableView.cellForRow(at: indexPath) as? DetailTableViewCell2 {
let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
cell.currentPageNumber.text = "\(String(Int(pageNumber) + 1))/\(hallImages?.ImagesHalls.count ?? 0)"
}
}
EDIT: cellForRowAt method
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell2 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! DetailTableViewCell2
cell2.currentPageNumber.text = "1/\(hallImages?.ImagesHalls.count ?? 0)"
cell2.descriptionLabel.text = hallImages?.hallDescription
cell2.nameLabel.text = hallImages?.studioName
cell2.addressLabel.text = hallImages?.studioAddress
cell2.priceLabel.text = hallImages?.hallPrice
cell2.metrs.text = hallImages?.hallMetrs
cell2.logoLabel.sd_setImage(with: URL(string: (hallImages?.studioLogo)!))
cell2.logoLabel.layer.cornerRadius = 5.0
cell2.logoLabel.clipsToBounds = true
return cell2
}