Created
March 4, 2014 00:17
-
-
Save nebiros/9337600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-03-03 19:14:21.346 ThreeThings[4782:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.' | |
*** First throw call stack: | |
(0x30c16e83 0x3af736c7 0x30c16d55 0x315bf0af 0x3339b413 0x33021943 0x3301d167 0x3301cff9 0x3301ca0d 0x3301c81f 0x3301654d 0x30be1f69 0x30bdf8f7 0x30bdfc43 0x30b4a471 0x30b4a253 0x358842eb 0x333ff845 0x8743d 0x3b46cab7) | |
libc++abi.dylib: terminating with uncaught exception of type NSException |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// THTAddThreeThingsTableHeaderView.m | |
// ThreeThings | |
// | |
// Created by Juan Felipe Alvarez Saldarriaga on 3/3/14. | |
// Copyright (c) 2014 3Things. All rights reserved. | |
// | |
#import "THTAddThreeThingsTableHeaderView.h" | |
#import <RHAddressBook/RHPerson.h> | |
@interface THTAddThreeThingsTableHeaderView () | |
@property (strong, nonatomic) RHPerson *person; | |
@end | |
@implementation THTAddThreeThingsTableHeaderView | |
- (id)initWithPerson:(RHPerson *)aPerson | |
{ | |
self = [self initWithFrame:CGRectZero]; | |
if (self) { | |
self.translatesAutoresizingMaskIntoConstraints = NO; | |
self.person = aPerson; | |
} | |
return self; | |
} | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
// Initialization code | |
} | |
return self; | |
} | |
/* | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect | |
{ | |
// Drawing code | |
} | |
*/ | |
- (void)layoutSubviews | |
{ | |
[super layoutSubviews]; | |
} | |
+ (BOOL)requiresConstraintBasedLayout | |
{ | |
return YES; | |
} | |
- (void)updateConstraints | |
{ | |
[super updateConstraints]; | |
[self setupTableViewHeader]; | |
} | |
#pragma mark - UI | |
- (void)setupTableViewHeader | |
{ | |
RHMultiStringValue *phoneNumbers = [self.person phoneNumbers]; | |
UIView *lastView; | |
for (NSString *phone in [phoneNumbers values]) { | |
if (!phone || [phone length] <= 0) { | |
continue; | |
} | |
UILabel *l = [[UILabel alloc] init]; | |
l.translatesAutoresizingMaskIntoConstraints = NO; | |
l.text = phone; | |
l.numberOfLines = 1; | |
l.lineBreakMode = NSLineBreakByTruncatingTail; | |
[self addSubview:l]; | |
if (lastView) { | |
NSDictionary *views = @{@"l": l, @"lastView": lastView ?: [NSNull null]}; | |
NSDictionary *metrics = @{@"margin": @10, @"height": @25}; | |
NSArray *cons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[lastView]-margin-[l(==height)]" | |
options:0 | |
metrics:metrics | |
views:views]; | |
[self addConstraints:cons]; | |
} else { | |
NSDictionary *views = @{@"l": l}; | |
NSDictionary *metrics = @{@"margin": @10, @"height": @25}; | |
NSArray *cons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-margin-[l(==height)]" | |
options:0 | |
metrics:metrics | |
views:views]; | |
[self addConstraints:cons]; | |
} | |
lastView = l; | |
} | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// self.navigationItem.title = self.person.name; | |
self.navigationItem.titleView = [self createNavBarTitleButton]; | |
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; | |
self.tableView.backgroundColor = [UIColor colorWithHexString:kTHTHexColorLightGray]; | |
self.tableView.separatorInset = UIEdgeInsetsZero; | |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; | |
self.headerView = [[THTAddThreeThingsTableHeaderView alloc] initWithPerson:self.person]; | |
// [self.headerView setNeedsUpdateConstraints]; | |
self.tableView.tableHeaderView = self.headerView; | |
[self setupNavBar]; | |
[self setupAddThingButton]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment