Reputation: 1667
I am adding a set of views into a mainview as follows.i.e 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];
}
Upvotes: 1
Views: 1164
Reputation: 2306
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;
Upvotes: 3