2013-06-12 25 views
5

Mục tiêu của tôi: để tập trung một chỉ số (theo chiều dọc và chiều ngang) để nút trong một cái nhìnđược cảnh báo cho autolayout, NSAutoLayout, khách quan C

Những gì tôi đang làm là:

[self.logInButton addConstraint:[NSLayoutConstraint constraintWithItem:spinner1 
                  attribute:NSLayoutAttributeCenterY 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:self.logInButton 
                  attribute:NSLayoutAttributeCenterY 
                  multiplier:1.0 
                   constant:0]]; 
[self.logInButton addConstraint:[NSLayoutConstraint constraintWithItem:spinner1 
                  attribute:NSLayoutAttributeCenterX 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:self.logInButton 
                  attribute:NSLayoutAttributeCenterX 
                  multiplier:1.0 
                   constant:0]]; 
self.logInButton addSubView:spinner 

Tuy nhiên, tôi đang nhận được cảnh báo bên dưới

The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x17e19390 UIActivityIndicatorView:0x17d035d0.centerY == UIButton:0x17df4430.centerY> 
    When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug. 
2013-06-12 17:37:19.610 FlipGive[366:60b] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x17e19810 UIActivityIndicatorView:0x17d035d0.centerX == UIButton:0x17df4430.centerX> 
    When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug. 

Có ai biết tôi đang làm gì sai ở đây không? Vui lòng giúp

Tất cả các nhận xét đều được hoan nghênh tại đây. Cảm ơn

+0

Thêm những hạn chế đến SuperView của cả hai nút và spinner. – Jano

+0

có giải thích nào cho nhận xét của bạn không? Tôi chỉ muốn hiểu deely – tranvutuan

+0

Tất cả các khung nhìn một tham chiếu ràng buộc phải nằm trong cây con của khung nhìn mà nó đang được thêm vào. Nói chung, thêm các ràng buộc vào tổ tiên gần nhất để có hiệu suất tốt hơn, hoặc thành phần mà nó hợp lý thuộc về (nút đăng nhập trong trường hợp này). – Jano

Trả lời

24

Bạn cần phải thêm chế độ xem trước khi thêm các ràng buộc.

đặt này đầu tiên và sau đó thêm các ràng buộc

self.logInButton addSubView:spinner 
+0

nó làm các trick. cảm ơn – tranvutuan

+0

Đã làm việc cho tôi. Cảm ơn bạn @THE_DOM – Xeieshan

+0

Yêu bạn. Nó làm việc cho tôi. Cảm ơn :) –

Các vấn đề liên quan