How to change view background color from other tableView?

Hi there

In themeTableView

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if (indexPath.section == 0 && indexPath.row == 0) {
            
            HappyView().view.backgroundColor = UIColor.systemBlue
            
        }
        
        if (indexPath.section == 0 && indexPath.row == 1) {
            
            HappyView().view.backgroundColor = UIColor.systemGreen
        }
        
    }

But the HappyView background color didn't change after I selected the cell and navigated to the HappView.

If I understand what your doing, your creating a new instance of HappyView() each time, changing the background color of its view, and then throwing it away.

The typical solution here is to remember what was selected (blue or green) and then when you want to navigate to HappyView() set the background color as part of navigating there.

How to change view background color from other tableView?
 
 
Q