I'm trying to hide a UIView and objects within it when a button is deselected. The button is located in a TableView section header contained in the same ViewController.
The button press is being stored in...
Activity.h
@property BOOL invitesAll;
Activity.m
#import "Activity.h"
@dynamic invitesAll;
And the rest of the code...
InviteContactsViewController.h
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *expirationViewHeightConstraint;
@property (weak, nonatomic) IBOutlet UILabel *timeToRespondLabel;
@property (weak, nonatomic) IBOutlet UISlider *expirationSlider;
@property (weak, nonatomic) IBOutlet UILabel *expirationLabel;
@property (strong, nonatomic) IBOutlet UIButton *inviteAll;
InviteesTableViewController.h
#import "InviteContactsViewController.h"
@property (weak, nonatomic) NSLayoutConstraint *expirationViewHeightConstraint;
@property (weak, nonatomic) UILabel *timeToRespondLabel;
@property (weak, nonatomic) UISlider *expirationSlider;
@property (weak, nonatomic) UILabel *expirationLabel;
InviteesTableViewController.m
#import "InviteesTableViewController.h"
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create button
InviteAllButton *inviteAllButton = [InviteAllButton buttonWithType:UIButtonTypeCustom];
[inviteAllButton setTitle:@"Order Matters" forState:UIControlStateSelected];
[inviteAllButton setTitle:@"Order Doesn't Matter" forState:UIControlStateNormal];
inviteAllButton.titleLabel.font = [UIFont fontWithName:@"Avenir" size:11.0];
inviteAllButton.titleLabel.numberOfLines = 2;
[inviteAllButton addTarget:self action:@selector(inviteAllAction:) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:inviteAllButton];
// set inviteAll button state
inviteAllButton.selected = !_activity.invitesAll;
// set constraints
[inviteAllButton setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *views = NSDictionaryOfVariableBindings(inviteAllButton, titleLabel);
[headerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[titleLabel]-(>=5)-[inviteAllButton(96)]-5-|" options:0 metrics:nil views:views]];
[headerView addConstraint:[NSLayoutConstraint constraintWithItem:inviteAllButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:headerView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
}
- (void)inviteAllAction:(UIButton *)sender {
sender.selected = !sender.selected;
_activity.invitesAll = !_activity.invitesAll;
[self validateReordering];
[self.tableView reloadData];
NSString *state = _activity.invitesAll ? @"invitesAll" : @"orderMatters";
// In my attempt to hide the view, I've set an expirationViewHeightConstraint
// and try to change its constant as the button is pressed
if (self.activity.invitesAll) {
self.expirationViewHeightConstraint.constant = 0.f;
self.timeToRespondLabel.hidden = YES;
self.expirationSlider.hidden = YES;
self.expirationLabel.hidden = YES;
} else {
self.expirationViewHeightConstraint.constant = 35;
self.timeToRespondLabel.hidden = NO;
self.expirationSlider.hidden = NO;
self.expirationLabel.hidden = NO;
}
}
I referenced Max's answer on changing the height constraint constant to 0.f and tried to follow Simon's answer on accessing properties across ViewControllers as a basis, but to no avail. When I run this nothing visible happens with the expirationViewHeightConstraint, timeToRespondLabel, expirationSlider, or expirationLabel IBOutlets when inviteAll is pressed.
I'm a newb so guessing I'm missing something basic here. Is my approach flawed?