tamtoum1987 tamtoum1987 - 3 months ago 9
Swift Question

addsubview the view not clickable

I'm adding a view like this



func clickChangeColor(nomAffaire : String, idEcoute : String, config : ConfigDto ){

let changeColorViewController = ChangeColorViewController()
changeColorViewController.showCustomAlertInView(self.view, message: "", button: "OK")


func showCustomAlertInView(targetView : UIView ,message : String, button : String)

but the view
is not clickable, only the behind is clicked when I click on the view that I add

in the image we can see the result, the problem is that the view that appear (in blue) is not clickable

enter image description here


@tamtoum I think i some what understand what you want. So first i am explaining what i understood. You have a view controller named ChangeColorViewController in which there is a view(a small one) which should be displayed on AffairesViewController. Now what i was not able to understand was why you are calling a method from AffairesViewController and then adding the ChangeColorViewController inside that method. Any ways I have a solution for you.

No need to call any method from to add subview, instead make properties for the data which you are passing in the method. Handel that data in ChangeColorViewController's viewDidiLoad(). Make following changes in your code:

func clickChangeColor(nomAffaire : String, idEcoute : String, config : ConfigDto ){

    let changeColorVC = self.storyboard?.instantiateViewControllerWithIdentifier("StoryBoardIdentifier") as! ChangeColorViewController

    /* pass data via properties here for eg.
       changeColorVC.message = "YourMessage"
       changeColorVC.button = "YourButtonText"



This answer is according to what i understood so far. If you have any more doubts then you may ask here.

Hope this will help you :)