简体   繁体   English

在子视图的子视图中禁用了用户交互

[英]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.

相关问题 如何在禁用用户交互的情况下为子视图实现longPressGestureRecognizer? - How implement longPressGestureRecognizer for subview with disabled user interaction? 在iOS 7的UIViewController上禁用了子视图用户交互 - subview user interaction disabled on UIViewController on iOS 7 加载subView时,在超级视图上禁用用户交互 - Disable user interaction on superview when subView is loaded 在Coverflow模式下启用特定SubView的用户交互 - Enable the user interaction for a specific SubView in Coverflow mode 防止UITableViewCell子视图上的交互 - Prevent interaction on subview of UITableViewCell Xcode 7:子视图禁用约束 - Xcode 7 : Constraints are disabled for subview 为子视图禁用用户交互会干扰对子视图的事件处理? - Disabling user interaction for subview interferes with event handling for superview? 在子视图上设置框架会禁用交互 - Setting frame on subview disables interaction Subview和UIViewController与代理之间的交互 - Interaction between Subview and UIViewController with Delegates 为什么UITableView不会获得任何用户交互,因为它的ViewController作为subView添加到UITabBarController - Why UITableView is not getting any user interaction as it's ViewController is added to a UITabBarController as subView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM