Tôi đang gặp sự cố với tính năng tự động điền trong dự án xcode 5
. Tôi đang sử dụng một bộ điều khiển xem đơn giản bên trong với một bộ điều khiển điều hướng. Tôi có một số MKMapView
ở nửa trên và UITableView
ở nửa dưới. Tôi đang sử dụng storyboards
và đã định cấu hình mẫu thử nghiệm UITableViewCell
, nhưng tôi đang thêm các ràng buộc thông qua mã. Tôi đã kiểm tra lại mọi điều khiển trong nguyên mẫu và không thấy bất kỳ ràng buộc nào được định cấu hình ở đó. Vấn đề của tôi xảy ra khi tôi thêm các ràng buộc cho UITableViewCell
. Tôi có mã sau trong các ô:Sự cố với Tự động hoàn tất trên UITableViewCell
-(void)updateConstraints {
[super updateConstraints];
//first remove old constraints
[self removeConstraints:self.constraints];
[self.nameLabel removeConstraints:self.nameLabel.constraints];
[self.addressLabel removeConstraints:self.nameLabel.constraints];
[self.rentableSquareFeetLabel removeConstraints:self.rentableSquareFeetLabel.constraints];
[self.lastSaleAmountLabel removeConstraints:self.lastSaleAmountLabel.constraints];
[self.lastSaleDateLabel removeConstraints:self.lastSaleAmountLabel.constraints];
[self.thumbnailImageView removeConstraints:self.thumbnailImageView.constraints];
//then set up constraints
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_thumbnailImageView, _nameLabel, _rentableSquareFeetLabel, _lastSaleAmountLabel, _addressLabel, _lastSaleDateLabel);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_thumbnailImageView(60)]-[_nameLabel(<=200)]-(>=8)-[_rentableSquareFeetLabel]-(>=8)-[_lastSaleAmountLabel]|" options:0 metrics:nil views:viewsDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_nameLabel]-(-4)-[_addressLabel]" options:NSLayoutFormatAlignAllLeading metrics:nil views:viewsDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_lastSaleAmountLabel]-(-4)-[_lastSaleDateLabel]" options:NSLayoutFormatAlignAllLeading metrics:nil views:viewsDictionary]];
}
Tôi nhận được thông tin sau trong bảng điều khiển gỡ lỗi. Ngoại lệ được kích hoạt bởi dòng addConstraints đầu tiên. Nếu tôi chỉ cần tiếp tục thông qua những sau đó cuối cùng tất cả mọi thứ xuất hiện như nó phải được, vì nó trông giống như xcode được lựa chọn để phá vỡ các hạn chế chính xác:
2013-09-25 15:07:14.169 PECProperties[32381:a0b] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) (
"<NSIBPrototypingLayoutConstraint:0x9d56c70 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIImageView:0x9d558f0](LTR) (Names: '|':UITableViewCellContentView:0x9d55620)>",
"<NSIBPrototypingLayoutConstraint:0x9d56d20 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x9d558f0(60)]>",
"<NSIBPrototypingLayoutConstraint:0x9d56d80 'IB auto generated at build time for view with fixed frame' H:|-(78)-[UILabel:0x9d559e0](LTR) (Names: '|':UITableViewCellContentView:0x9d55620)>",
"<NSLayoutConstraint:0x9d53830 H:[UIImageView:0x9d558f0]-(NSSpace(8))-[UILabel:0x9d559e0]>")
Will attempt to recover by breaking constraint <NSIBPrototypingLayoutConstraint:0x9d56d80 'IB auto generated at build time for view with fixed frame' H:|-(78)-[UILabel:0x9d559e0](LTR) (Names: '|':UITableViewCellContentView:0x9d55620)>
Break on objc_exception_throw to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Các NSIBPrototypingLayoutConstraint thứ ba cho thấy 78 điểm giữa các cạnh của quan điểm và một nhãn. Đó là nơi nguyên mẫu được định vị gần (và nếu tôi di chuyển nó trong nguyên mẫu, tôi thấy sự thay đổi trong ràng buộc trong bảng điều khiển gỡ lỗi), nhưng xung đột với khoảng cách "chuẩn" của riêng tôi giữa chế độ xem hình ảnh và nhãn .
Tôi đã thử đặt translatesAutoresizingMaskIntoConstraints=NO
trong bộ điều khiển của chế độ xem cellForRowAtIndexPath
, nhưng điều đó dường như không giúp được gì. Làm thế nào tôi có thể sửa bố cục?
Tôi nhận thấy lỗi từng người một trong iOS7 gây ra sự cố tương tự. Tôi đã xác định tất cả các ràng buộc trong IB và XCode là hạnh phúc. Nhưng tổng của tất cả các kích thước dọc trong ngoại lệ
Matt