Vee Vee - 1 month ago 19
iOS Question

Buttons/Links under view object in .xib file are not responding

Can somebody tell me why none of the buttons under the "License Agreement View" UIView object in my .xib file are triggering an action? It seems that the Scrollview object is messing up the behavior. When the buttons are directly under the "Scroll View" object (as opposed to the "License Agreement View" UIView object), then they function properly. But, I need to group my buttons under the UIViews as shown in the view hierarchy below.

Here's the view layout:

enter image description here

Here's my view hierarchy:

enter image description here

Here's the corresponding .m file:

@interface MYViewController ()
- (IBAction)licenseAgreementPressed:(id)sender;
- (IBAction)legalDisclaimerPressed:(id)sender;
- (IBAction)privacyStatementPressed:(id)sender;

@property (strong, nonatomic) IBOutlet UIView *licenseAgreementView;
@property (weak, nonatomic) IBOutlet UIButton *legalDisclaimerButton;
@property (strong, nonatomic) IBOutlet UIButton *privacyStatementButton;
@end

@implementation MYViewController
- (IBAction)licenseAgreementPressed:(id)sender
{
NSLog(@"Pressed A");
}

- (IBAction)legalDisclaimerPressed:(id)sender
{
NSLog(@"Pressed B");
}

- (IBAction)privacyStatementPressed:(id)sender
{
NSLog(@"Pressed C");
}
@end

Vee Vee
Answer

So the problem was the links, buttons, and text fields were not actually located within the bounds specified the parent views because the original .xib file didn't have the required constraints pinned to those elements. I discovered this by checking the "clip to bounds" checkbox in the Attributes Inspector pane. Whenever "clip to bounds" was checked, the app was NOT displaying any of the above view objects; I could only see links, buttons, and text fields when "clip to bounds" was unchecked but unfortunately, those elements were not clickable at that point. After setting the necessary constraints, however, the view elements were correctly placed within the bounds of their parent views and the text fields, labels, and buttons became clickable. I'm attaching the constraints that I used to fix the problem. Note: the constraints that are not expanded only include a height constraint.

enter image description here