我在FooterView中设置了一个按钮,它属于一个collectionView,它在一个TableView中。如何从此按钮获取 indexPath.section?
这是一个新的分段控件的选项卡。过去,我尝试将 indexPath.section 分配给 int 变量,甚至将数字分配给常量,在单元格中使用 prepareForReuse 方法来更新单元格,但它总是给我错误的索引。当我滚动时它会改变。
var currentlyActiveCellIndexPath: Int?
extension LibraryViewController {
func viewTapped(button: UIButton) {
let tapgesture = UITapGestureRecognizer.init(target: self, action: #selector(goToViewAllArticles))
button.addGestureRecognizer(tapgesture)
let tapgesture1 = UITapGestureRecognizer.init(target: self, action: #selector(goToViewAllPodcasts))
button.addGestureRecognizer(tapgesture1)
tapgesture.numberOfTapsRequired = 1
button.isUserInteractionEnabled = true
}
@objc func goToViewAllArticles(sender: UITapGestureRecognizer) {
return self.performSegue(withIdentifier: "showBrowseFromButton", sender: currentlyActiveCellIndexPath)
}
@objc func goToViewAllPodcasts(sender: UITapGestureRecognizer) {
return self.performSegue(withIdentifier: "showBrowseFromButton", sender: currentlyActiveCellIndexPath)
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
currentlyActiveCellIndexPath = indexPath.section
我希望 indexPath.section 保持不变,但是一旦滚动,它就会改变,我无法获得正确的 indexPath.section。