I have 2 Container Views which have a UITableViewController(sideMenuVC) and a UICollectionViewController(centerVC) embedded inside respectively and my CollectionVC is inside a navigation controller itself. I have put these two Container Views inside a third VC which is the rootVC. Now I am trying to show content in my centerVC based on the row that is selected in the sideMenuVC and I am using delegates, however, the delegate is nil when I try to call it from the sender. I have tried setting the delegate as weak and also setting the delegate in awakeFromNib instead of viewDidLoad, I have also tried to set the delegate from different VCs.
Here is my protocol:
import Foundation
import Photos
protocol sideMenuDelegate {
func handleRowSelection(title: String, fetchResult: PHFetchResult<PHAsset>, assetCollection: PHAssetCollection?)
}
and this is how I set the delegate inside the third VC which holds both Container Views:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
sideMenuVC = storyboard.instantiateViewController(withIdentifier: "sideVC") as? SideMenuViewController
centerVC = storyboard.instantiateViewController(withIdentifier: "centerVC") as? centerViewController
sideMenuVC?.delegate = centerVC
I have also tried setting it in my centerVC like so:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
sideMenuVC = storyboard.instantiateViewController(withIdentifier: "sideVC") as? SideMenuViewController
sideMenuVC?.delegate = self
and finally this is the implementation of the delegate func:
extension centerViewController: sideMenuDelegate {
func handleRowSelection(title: String, fetchResult: PHFetchResult<PHAsset>, assetCollection: PHAssetCollection?) {
pageTitle = title
inFetchResult = fetchResult
inAssetCollection = assetCollection
}
}
I think the problem is with accessing the correct instance of VCs from the storyboard but I couldn't find any way to fix it.