【发布时间】:2019-01-29 07:10:01
【问题描述】:
在UITableView(水平滚动)numberOfRowsInSection 是动态数字。在UICollectionView(垂直滚动)numberOfItemsInSection 也是动态的。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (self.arrayNewsfeedsList[intIndex]as! Newsfeeds).media!.count//3
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sliderCollectionViewCell", for: indexPath) as! sliderCollectionViewCell
let stringImageUrl = "https://img.youtube.com/vi/CQElIZzzlpc/hqdefault.jpg"
cell.imageViewSlider.setKRImageUrl(url:stringImageUrl) { (imageUser) in
cell.imageViewSlider.image = imageUser
}
return cell
}
在滚动 scrollViewDidEndDecelerating 和 scrollViewDidEndScrollingAnimation 时,应用程序崩溃了。
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let cell = tableviewNewsfeed.cellForRow(at: NSIndexPath(row: 0, section: intIndex) as IndexPath)as! NewsfeedTableViewCell
cell.pagecontrolYoutube?.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width - 50)
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
let cell = tableviewNewsfeed?.cellForRow(at: NSIndexPath(row: 0 , section: intIndex) as IndexPath)as! NewsfeedTableViewCell
cell.pagecontrolYoutube?.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width - 50)
}
如何更新这一行?
tableviewNewsfeed?.cellForRow(at: NSIndexPath(row: 0 , section: intIndex) as IndexPath)as! NewsfeedTableViewCell
请参阅此图片以供参考:https://imgur.com/a/oG4nLtc
【问题讨论】:
-
那么
nil到底是什么?当编译器停止时,请在控制台中输入:po tableviewNewsFeed -
> 链接 po tableviewNewsFeed: imgur.com/a/NmiVqyb
-
在 cellForRowAt 中,我更新了 Indexpath.section 。 intIndex = indexPath.section
-
这打印什么?
po tableviewNewsfeed.cellForRow(at: IndexPath(row: 0, section: intIndex)) -
>输出:无。如何在滚动 tableview 时更新 Indexpath 值?
标签: swift scroll uicollectionview tableview