2016-06-03 3 views
0

viewController의 viewDidLoad()에서 UITableView를 슈퍼 뷰로 제한하면 모든 것이 완벽하게 작동합니다. 나는이 같은 layoutGuide의 상단에있는 tableView을 제한하려고하면topLayoutGuide에 제약 조건을 프로그래밍 방식으로 추가 하시겠습니까?

그러나 :

// tableView.top = view.top 
myConstraint =[NSLayoutConstraint 
       constraintWithItem:theTableView 
       attribute:NSLayoutAttributeTop 
       relatedBy:NSLayoutRelationEqual 
       toItem:self.view 
       attribute:NSLayoutAttributeTop 
       multiplier:1.0 
       constant:0]; 
myConstraint.identifier = @"tableView.top = layoutguide.bottom"; 
[self.view addConstraint:myConstraint]; 

는이 오류 얻을 :

[UIViewController topLayoutGuide]: guide not available before the view controller's view is loaded 
2016-06-03 10:48:06.310 BlinkPDF[304:34590] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs' 

내가에 내 모든 제약 조건을 이동 시도를 - (void) viewController의 updateConstraints 메서드를 사용하여 런타임 오류를 제거하고 뷰를 올바르게 렌더링했지만 장치를 회전하면 뷰가 제대로 업데이트되지 않았습니다.

누구나 그 제약 조건을 쓸 정확한 장소를 알려줄 수 있습니까?

감사합니다.

답변

0
Try to call your updateConstraints to viewDidAppear and add this line before calling method 

    tableView.translatesAutoresizingMaskIntoConstraints = NO; 

So your viewDidAppear method will be like 

    - (void)viewDidAppear:(BOOL)animated{ 
     [super viewDidAppear:animated]; 
     [self updateConstraints]; 
    } 

도움이 될 것입니다.

관련 문제