Trong dự án của tôi, tôi đã sử dụng một tableView bên trong một collectionView và tôi cũng sử dụng một pageControl. Khi tôi vuốt chế độ xem bộ sưu tập theo chiều ngang, tôi cũng muốn chuyển đổi pageControl, nhưng nó không hoạt động đúng cách. Tôi đã sử dụng phương pháp scrollViewDidScroll
để chuyển đổi pageControl
thành số collectionView
Swipes. Nhưng vấn đề là, khi tableView cuộn scrollViewDidScroll
phương pháp một lần nữa sẽ gọi. Vì vậy, có cách nào khác hoặc bất kỳ giải pháp nào để khắc phục sự cố này.Cách sử dụng trangControl trong Collectionview Bên trong Tableview?
Kiểm tra liên kết bên dưới.
TableView Phương pháp
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return model.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! FbHomeCell
cell.btnPushImage.tag = indexPath.row
cell.collectionView.tag = indexPath.row
return cell
}
CollectionView Phương pháp
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return model[collectionView.tag].count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
collCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! FBHomeCollectionCell
collCell.backgroundColor = model[collectionView.tag][indexPath.item]
collCell.pageControlSwipe.numberOfPages = Int(collectionView.contentSize.width/collectionView.frame.size.width)
return collCell
}
Scroll Xem Đại biểu Phương pháp
func scrollViewDidScroll(_ scrollView: UIScrollView)
{
let pageWidth = scrollView.frame.width
collCell.pageControlSwipe.currentPage = Int((scrollView.contentOffset.x + pageWidth/2)/pageWidth)
collCell = cell.collectionView.cellForItem(at: IndexPath (item: scrollView.tag, section: 0)) as! FBHomeCollectionCell
}
Cảm ơn và đánh giá cao sự giúp đỡ ..
có tác phẩm của nó nhưng một lần nữa khi sẽ cuộn bộ sưu tập xem trên hàng tiếp theo của tableview thì lần xem thứ 1 thu thập hiển thị pagecontrol từ 0 chỉ mục. – ashmi123
@ ashmi123 Kích thước ô của bộ sưu tập của bạn có phải là kích thước xem của bạn không, có nghĩa là kích thước thiết bị? –
Không chờ đợi sẽ cho bạn thấy những gì chính xác muốn từ đó u có ý tưởng. – ashmi123