Heena
Heena

Reputation: 2358

Not getting Button click event in View added in Container View

I have created one common view for the application where I have added container view.

This is a confusing structure also very common question for SO but I am stuck since a day..

In my case hierarchy is as

ViewController's View -> (within that) commonview's container view -> (within that)I am adding one another view(base view) with two views.(view 1,view 2)

 [self.commonView.containerView addSubview:baseView];
 [baseView addSubview:view1];
 [baseView addSubview:view2];
 [self.view addSubview:self.commonView];

For that I am getting click events for view1's buttons but not for the view2's buttons.

I have checked userInteraction and all other common things. Now I am not getting what is wrong. Also this structure is already used in application so I wont be able to change it.I just have to resolve this issue.

Upvotes: 2

Views: 1679

Answers (3)

spaleja
spaleja

Reputation: 1435

Please check, if you have applied Gesture to any view then make cancelsTouchesInView property of gesture to NO. By default, it is TRUE, so button inside that view may not get touch as gesture cancels its inner view's touch. If this is not the case, then apply Gesture to your button as this can happen when there are many hierachy of controls.

Upvotes: 2

V.J.
V.J.

Reputation: 9590

you need to add in respective order.

First add base view1 & view2 into baseView

[baseView addSubview:view1];
[baseView addSubview:view2];

and then add baseView into ContainerView

[self.commonView.containerView addSubview:baseView];

at last add commonView in mainView

[self.view addSubview:self.commonView];

Note :-

If you are adding the viewcontroller into the current viewcontroller then you need to write below code.

[self addChildViewController: yourviewController];

Then your button click will be worked.

Upvotes: 0

Niru Mukund Shah
Niru Mukund Shah

Reputation: 4733

I think you should try by bringing your subview(i.e. view1) to front, since it is getting hide by another subview (i.e. view2)

You should first try with [self.view bringSubviewToFront:self.commonView.containerView ]; only.

if this works then it's Good otherwise try with this both shown as following

[self.view bringSubviewToFront:self.commonView.containerView ];
[self.view bringSubviewToFront:view1];

Hope this is helpful to you!

Enjoy Programming!

Upvotes: 0

Related Questions