Reputation: 2057
I'm adding a view like this
In AffairesViewController
:
func clickChangeColor(nomAffaire : String, idEcoute : String, config : ConfigDto ){
let changeColorViewController = ChangeColorViewController()
changeColorViewController.showCustomAlertInView(self.view, message: "", button: "OK")
}
In ChangeColorViewController
:
func showCustomAlertInView(targetView : UIView ,message : String, button : String)
{
targetView.addSubview(self.view)
}
but the view ChangeColorViewController
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
Upvotes: 0
Views: 2368
Reputation: 1895
@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"
*/
self.addChildViewController(changeColorVC)
self.view.addSubView(changeColorVC.view)
}
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 :)
Upvotes: 3
Reputation: 56
If the subview you are adding is outside the bounds of the superview, than no touches will be detected on the subview. Check for this
Upvotes: 1
Reputation: 5588
When you add a view, userInteraction
is disabled by default. just add view.userInteractionEnabled = true
Upvotes: 0