I want to change the background image in the Viewcontroller when one of the side menu items is clicked.
I am using VIP architecture while doing this process.
When the item on the side menu is clicked, the following code block works:
else if indexPath.row == 1
{
switch indexPath.section {
case 0:
print("Any ")
print(indexPath)
case 1:
print("Dark Mode ")
// self.interactor?.selectThemes(theme: "Dark")
router?.changeTheme(theme: .Dark)
case 2:
print("Once a day ")
default:
print("out of range")
}
}
then there is something I want to do on the router:
func changeTheme(theme:Themes){
if Themes.Dark == theme
{
var jokegenerate = JokeGenerateController()
jokegenerate.changeBackground(image: UIImage(named: "duck")!)
//print(theme)
}
}
Finally, I want to change the image in the viewController. my code is below:
func changeBackground(image: UIImage){
backGroundImage.image = image
print("hey")
}
But I am getting the following error here: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
What should I do to fix the error?
You should check this link (delegate)
You should create connections between modules.
Something like that.