iOS/트러블 슈팅

트러블슈팅) Thread 1: "Unable to activate constraint with anchors....

Brad_Heo 2024. 6. 19. 15:17

코드로 UI 작업 시 발생한 에러 메세지

에러 메세지

Thread 1: "Unable to activate constraint with anchors <NSLayoutDimension:0x280310780 \"UILabel:0x10450aa60.width\"> and <NSLayoutDimension:0x2803107c0 \"UIView:0x10450b200.width\"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal."

번역

스레드 1: "앵커 <NSLayoutXAxisAnchor:0x3034d7040 \"UIView:0x108926da0.leading\"> 및 <NSLayoutXAxisAnchor:0x3034d6f80 \"UIView:0x108926940.leading\"을 사용하여 제약 조건을 활성화할 수 없습니다. 공통 조상이 없기 때문에 제약 조건이나 앵커가 다른 뷰 계층의 항목을 참조합니까? 그것은 불법입니다."

먼가 제약조건이 안맞고, 앵커 잡는 뷰계층이 꼬인 것 같다.

이럴 땐 바로 구글검색...

다행히 나만 발생된 에러가 아니였다.

스택오버플로우에서 답변을 쉽게 찾을 수 있었다.

요약하자면,, 먼저 addView를 하고 Layout을 잡으라는 의미 -> 현재 내 코드가 Layout을 잡고 addView를 한 상황이다.

바로 적용해보자..

성공!

참고자료

https://stackoverflow.com/questions/47168059/unable-to-activate-constraint-with-anchors