Uitableview 如何在collectionview内部的tableview中获取选定索引
UITableView->表格视图单元格->集合视图->集合视图单元格 单击“集合视图单元格”时,仅获取集合视图单元格的选定索引。如何在表视图中获取索引Uitableview 如何在collectionview内部的tableview中获取选定索引,uitableview,uicollectionview,uicollectionviewcell,Uitableview,Uicollectionview,Uicollectionviewcell,UITableView->表格视图单元格->集合视图->集合视图单元格 单击“集合视图单元格”时,仅获取集合视图单元格的选定索引。如何在表视图中获取索引 谢谢。如果你想切换到另一个视图,你可以使用prepare在你的UIViewController中切换,并获取tableView索引 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier
谢谢。如果你想切换到另一个视图,你可以使用prepare在你的
UIViewController
中切换,并获取tableView索引
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "segueHomeToDetail" {
if let collectionCell: InfoCellView = sender as? InfoCellView {
if let collectionView: UICollectionView = collectionCell.superview as? UICollectionView {
if let destination = segue.destinationViewController as? DetailViewController {
// Pass some data to YourViewController
// collectionView.tag will give your selected tableView index
destination.object = collectionCell.object
}
}
}
}
}
我在我的代码中使用了这个选项,效果很好。如果你想切换到另一个视图,你可以使用prepare to segue在你的
UIViewController
中切换,并获取tableView索引
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "segueHomeToDetail" {
if let collectionCell: InfoCellView = sender as? InfoCellView {
if let collectionView: UICollectionView = collectionCell.superview as? UICollectionView {
if let destination = segue.destinationViewController as? DetailViewController {
// Pass some data to YourViewController
// collectionView.tag will give your selected tableView index
destination.object = collectionCell.object
}
}
}
}
}
我在代码中使用了这个方法,效果很好。实现ScrollView方法,在Tableview和Collection视图之外获取索引值
if scrollView == tableview {
let contentOffset = scrollView.contentOffset.y
print("contentOffset: ", contentOffset)
if (contentOffset > scrollView.contentOffset.y) {
print("scrolling Down")
} else {
print("scrolling Up")
}
}
else{
let pageWidth = scrollView.frame.size.width
let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
let index = IndexPath(row:(scrollView.tag),section:0) //scrollview.tag get the index value of tableview when collection view scroll
}
实现ScrollView方法以获取Tableview和Collection视图之外的索引值
if scrollView == tableview {
let contentOffset = scrollView.contentOffset.y
print("contentOffset: ", contentOffset)
if (contentOffset > scrollView.contentOffset.y) {
print("scrolling Down")
} else {
print("scrolling Up")
}
}
else{
let pageWidth = scrollView.frame.size.width
let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
let index = IndexPath(row:(scrollView.tag),section:0) //scrollview.tag get the index value of tableview when collection view scroll
}