2

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.

Heena
  • 2,348
  • 3
  • 32
  • 58

3 Answers3

2

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.

Rahul Mane
  • 1,005
  • 18
  • 33
spaleja
  • 1,435
  • 15
  • 24
0

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!

Niru Mukund Shah
  • 4,637
  • 2
  • 20
  • 34
  • No its not like that view1 has height 44 and view2 is starting with y=44. And I am getting click of view1's buttons but not view2's buttons – Heena Jul 26 '13 at 04:43
  • yes, I know, but if your view2 is overwriting your view1 then the view1 will not reflect anything or doesn't respond. I recommend you to try this solution once! – Niru Mukund Shah Jul 26 '13 at 04:45
  • As I told you view2 is added below the view1 and I am getting clicks for view1 and not for view2. Also I told you that I have tried with `[self.commonView.containerView bringSubviewToFront:baseview];` – Heena Jul 26 '13 at 04:51
  • This is also not working..:( Also If I tried to change the background colors of these view1 and view2 from the code. Those are not reflecting... – Heena Jul 26 '13 at 04:59
  • yes, there is an issue with hierarchy. Need to check your code thoroghly for that. – Niru Mukund Shah Jul 26 '13 at 05:04
0

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.

V.J.
  • 9,492
  • 4
  • 33
  • 49