简体   繁体   中英

User Interaction disabled in subview of a subview

I am adding a set of views into a mainview as follows.ie I have a view which contains a set of subviews (Label,Button etc).then this view added to the mainview. My ptoblem is when I tapped in the Button in the View its IBAction not invoked. My question is how invoke the Button tap action inside the subview of mainView?

for (int i = 0;i < controls.count;i++) {
         UIView *view = [[UIView alloc]init];
         view.userInteractionEnabled = YES;
            for (int j=0; j<viewsArray.count; j++) {

                  UIView *subView = viewsArray[i]; // this may be Button, Label etc
                  subView.tag = controlCount++;
             [view addSubview:subView];
            }
            [self.mainView addSubview:view];
        }

The problem is that the UIView (the variable view ) frame isn't set (it's 0,0,0,0).

Change to:

UIView *view = [[UIView alloc]initWithFrame:<a frame>];

where <a frame> could be CGRectMake(0, 0, 50, 50) for example.

The subview of that view should also have it's frame set. Remember that the views ( subview ) frame refers to the frame in its parent view (in your case view )

You can remove view.userInteractionEnabled = YES;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM