[英]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. 我的ptoblem就是当我点击View中的Button时,它的IBAction
没有被调用。 My question is how invoke the Button tap action inside the subview of mainView? 我的问题是如何在mainView的子视图中调用Button tap动作?
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). 问题是没有设置UIView(变量view
)框架(它是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. 例如, <a frame>
可以是CGRectMake(0, 0, 50, 50)
。
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
) 请记住,视图( subview
)框架是指其父视图中的框架(在您的案例view
)
You can remove view.userInteractionEnabled = YES;
你可以删除view.userInteractionEnabled = YES;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.