0
votes

Have a nice weekend. I have problem about that under the didSelectItemAt indexPath function I want to go new view controller which is show details and each cell must have different view controller (it will change according to data which are came from protocol). I tried lots of way to do that but I can't figured out. I call present and push view controller codes but its also not working because navigationController code can't work under didSelectItemAt function. Lastly I tried that:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let homecon = HomeController()
    homecon.showDetailPage() }


func showDetailPage() {
    let newView = pageDetail()
    self.present(newView, animated: true, completion: nil)

}

(showDetailPage function from HomeController). But that code also gave error which is

'UICollectionView must be initialized with a non-nil layout parameter'.

So I can't solve it. How can I solve it please help me. Have a nice work!

1

1 Answers

0
votes

This is because HomeController is a subclass of UICollectionViewController and a collectionViewController can not be initialized without it's layout!

So use this initializer instead:

let homecon = HomeController(collectionViewLayout: UICollectionViewLayout())

Oh and it's just the start of the week here.