I have a UICollectionView with images. I implemented a SideMenu that contains a TableView when I select an item in the SideMenu I want it to automatically scroll to a specific row in the CollectionView
What do I do in didSelectRowAt
?
Here is my full ViewController Class below
import SideMenu
import UIKit
class ViewController: UIViewController {
var menu: SideMenuNavigationController?
@IBOutlet weak var collectionView: UICollectionView!
var imgArr = ["1","2","3","4","5","6","7","8","9","10"]
override func viewDidLoad() {
super.viewDidLoad()
menu = SideMenuNavigationController(rootViewController: MenuListController())
menu?.leftSide = true
SideMenuManager.default.leftMenuNavigationController = menu
SideMenuManager.default.addPanGestureToPresent(toView: self.view)
}
@IBAction func didTapMenu(){
present(menu!, animated: true)
}
}
extension ViewController : UICollectionViewDataSource, UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imgArr.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? DataCollectionViewCell
cell?.img.image = UIImage(named:imgArr[indexPath.row])
return cell!
}
}
class MenuListController:UITableViewController{
var items = ["First", "Second"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableView.self, forCellReuseIdentifier: "cellmenu")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellmenu", for: indexPath)
cell.textLabel?.text = items[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
print("selected " + items[indexPath.row])
// WHAT DO I DO HERE????
}
}