Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created March 3, 2014 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebiros/9330034 to your computer and use it in GitHub Desktop.
Save nebiros/9330034 to your computer and use it in GitHub Desktop.
- (void)updateViewConstraints
{
[self setupTableViewHeader];
[super updateViewConstraints];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// CGRect frame = CGRectZero;
// frame.size.width = self.tableView.bounds.size.width;
// frame.size.height = [self.headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
// if (self.tableView.tableHeaderView != self.headerView || !CGRectEqualToRect(frame, self.headerView.frame)) {
// self.headerView.frame = frame;
// [self.headerView layoutIfNeeded];
// self.tableView.tableHeaderView = self.headerView;
// }
[self.headerView layoutSubviews];
self.tableView.tableHeaderView = self.headerView;
}
- (void)setupTableViewHeader
{
RHMultiStringValue *phoneNumbers = [self.person phoneNumbers];
UIView *lastView;
CGFloat height = 25;
NSMutableArray *labels = [NSMutableArray array];
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
for (NSString *phone in [phoneNumbers values]) {
if (!phone || [phone length] <= 0) {
continue;
}
UILabel *l = [[UILabel alloc] init];
l.text = phone;
l.numberOfLines = 1;
l.lineBreakMode = NSLineBreakByTruncatingTail;
// [self.tableView.tableHeaderView addSubview:l];
[self.headerView addSubview:l];
[l mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lastView ? [lastView mas_bottom] : @(padding.top));
make.left.equalTo(@(padding.left));
// make.width.equalTo(contentView.width);
make.height.equalTo(@(height));
}];
[labels addObject:l];
// height += 25;
lastView = l;
}
// [self.tableView.tableHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(labels);
// make.height.equalTo(@(height));
}];
// UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
// [[phoneNumbers values] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// NSString *p = (NSString *) obj;
//
// UILabel *l = [[UILabel alloc] init];
// l.text = p;
// l.numberOfLines = 1;
// l.lineBreakMode = NSLineBreakByTruncatingTail;
// l.tag = idx;
//
// if (0 == idx) {
// l.tag = 666;
//
// [self.tableView.tableHeaderView addSubview:l];
//
// [l mas_makeConstraints:^(MASConstraintMaker *make) {
// make.edges.equalTo(self.tableView.tableHeaderView).with.insets(padding);
// }];
// } else {
// [self.tableView.tableHeaderView addSubview:l];
//
// [l mas_makeConstraints:^(MASConstraintMaker *make) {
//// make.edges.equalTo().with.insets(padding);
//// make.top.equalTo
// }];
// }
// }];
}
2014-03-03 12:26:22.191 ThreeThings[4216:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. THTAddThreeThingsTableViewController's implementation needs to send -layoutSubviews to the view to invoke auto layout.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment