0
Я попытался реализовать UITapGestureRecognizer
, чтобы получить indexPath.row
из collectionView
от tableView
.Получить индексную таблицу UICollectionView от UITable в пределах
Я тоже пробовал делегировать, но он, похоже, не работает.
protocol PassingCellDelegate {
func passingIndexPath(passing: KitchenVC)
}
class ViewController: UIViewController {
let tap = UITapGestureRecognizer(target: self, action: #selector(tapSwitchTableViewCollection))
var delegate: PassingCellDelegate?
@IBAction func buttonCompletedTapped(sender: AnyObject) {
delegate?.passingIndexPath(passing: self)
}
func tapSwitchTableCollection(sender: UITapGestureRecognizer) {
if let cell = sender.view as? KitchenCollectionViewCell, let indexPath = collectionKitchen.indexPath(for: cell) {
if self.selectedIndexPaths == indexPath {
print("This in IF")
print(indexPath)
self.selectedIndexPaths = IndexPath()
} else {
print("This in ELSE")
print(indexPath)
self.selectedIndexPaths = indexPath
}
}
}
Cell класс, где tableView
содержится в CollectionViewCell
class CollectionCell: UICollectionViewCell, UITableViewDelegate, UITableViewDataSource, PassingCellDelegate {
func passingIndexPath(passing: KitchenVC) {
passing.tapSwitchTableCollection(sender: passing.tap)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var cell: UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "OrdersCell")
if tableView == ordersTableView {
passingIndexPath(passing: KitchenVC())
}
}
Я получил метод tapSwitchTableCollection
с этого поста:
Нажмите here!
делать и иметь представление коллекции внутри Tableview? – Aragunz
У меня есть tableView внутри коллекцииView и хотел бы получить indexPath.row из tableView внутри него. Я не могу использовать didSelectItemAt из коллекцииView, потому что я хочу, чтобы кран был запущен из таблицыView в didSelectRowAt – Christian
У меня была аналогичная проблема, когда у меня была коллекцияView внутри tableView, которая довольно то же самое. Если вы знакомы с Objective C, и я покажу вам некоторый код, как я достиг этого без использования жестов. Пожалуйста, дайте мне знать, если вы заинтересованы в том, чтобы я отправлял ответ. – Aragunz