Error 가 보통
because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal
으로 처리될 것이다.
UI를 선언하는 클로저가 연산 프로퍼티인지 확인하자.
많이 나오는 에러 해결 방법은 addsubview를 통해서 에러를 해결한다고 기재되어 있다. 하지만 나는 addsubview또한 정확한 언어로 해결했다. 한 두시간 얼타고 확인한 것은 클로저가 UI가 아닌 computeProperty로 정의되어 있었던 것이다.
//정상 코드
var testLabel: UILabel = {
let lb = UILabel()
lb.text = "이거 출력 됨?"
lb.translatesAutoresizingMaskIntoConstraints = false
return lb
}()
//연산 프로퍼티
var testLabel: UILabel{
let lb = UILabel()
lb.text = "이거 출력 됨?"
lb.translatesAutoresizingMaskIntoConstraints = false
return lb
}
따라서 문제가 발생헀던 것이다. UI선언할 때 연산 프로퍼티를 활용하지 않도록 조심하도록 하자!
에러 전문
2023-08-08 23:22:41.987704+0900 HotCoffeeProgramtically[34029:422819] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <nslayoutyaxisanchor:0x6000021bfe40 "uitableview:0x12802ae00.top"> and <nslayoutyaxisanchor:0x6000021bf980 "uilayoutguide:0x600000ddcd20'uiviewsafearealayoutguide'.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'</nslayoutyaxisanchor:0x6000021bf980 "uilayoutguide:0x600000ddcd20'uiviewsafearealayoutguide'.top"></nslayoutyaxisanchor:0x6000021bfe40 "uitableview:0x12802ae00.top">
'Swift > UIKit' 카테고리의 다른 글
[UIKit] UICollectionView Compostional Layout 으로 TableView만들기 (WWDC20 List in UIColelctionView ) (0) | 2024.01.24 |
---|---|
[UIKit] iOS 트러블 슈팅 UIStackView Distribution 이해하기 (0) | 2024.01.23 |
[RxSwift]왜 비동기 처리가 안되는거지? viewDidLoad에서 onNext가 실행이 안될때... (부제: viewdidload에 disposableBag을 선언하면 생기는 일) (1) | 2023.03.23 |
[UIKit] RxSwift로 tableview만들기 (0) | 2023.03.22 |
[UIkit] Tableview 코드로 만들기 (0) | 2023.03.21 |