mam subview że chcę zachować przystanków podczas ekran obraca się, więc postanowiłem umieścić typ NSLayoutConstraint:
Trailing Space Superview
górę Space to Superview
Przestrzeń przycisków do Superview
Jestem w podklasie UITableViewCell. Napisałem kod, ale pojawia się następujący błąd:
„NSInvalidArgumentException”, powód: „Nie można przeanalizować formatu ograniczeń”
'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
self is not a key in the views dictionary.
H:[self.arrows]-5-|
Mój kod w CustomCell.m jest:
self.arrows = [[Arrows alloc]initWithFrame:CGRectMake(self.contentView.bounds.size.width-30, self.bounds.origin.y+4, 30, self.contentView.bounds.size.height-4)];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(self.arrows, self.contentView);
NSMutableArray * constraint=[[NSMutableArray alloc]init];
[constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H: [self.arrows]-5-|" options:0 metrics:nil views:viewsDictionary]];
[constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-1-[self.arrows]" options:0 metrics:nil views:viewsDictionary]];
[constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"[V: [self.arrows]-1-|" options:0 metrics:nil views:viewsDictionary]];
[self.arrows addConstraints:constraint];
Dziękuję bardzo –
Dość śmieszne, że docs podać przykłady z użyciem 'NSDictionaryOfVariableBindings' do tworzenia słownika, ale nie wspomnieć, że nie będzie działać z każdą własność lub IBOutlets –
Jonathan, sam byłem tym trochę zdezorientowany. Dokumenty wyraźnie stwierdzają, że używają tej metody. Po prostu pomyślałem, że to wystarczająco inteligentne, by usunąć siebie. część klucza automatycznie. – Nailer