修改:
现在,在删除自动布局后,它仅适用于较小的设备,如iPhone 4,4s,但它不适用于iPhone 6 iOS 9.1.2。如果我添加一个高度为80的空白部分标题,它可以在iPhone 6中运行。仍然想知道可能是什么问题?
原始问题: 我创建了一个UIView子类,并为它创建了一个nib。 我已将它分配给我的tableHeaderView,但问题出在笔尖我的视图高度为200像素,在代码中我需要手动将高度设置为300像素。这是代码
//Create and add header
self.header = [[[NSBundle mainBundle] loadNibNamed:@"LeftMenuHeaderViewViewController" owner:nil options:nil] lastObject];
self.header.frame = CGRectMake(0, 0, 260, 300);
self.header.target = (id)self;
// self.header.backgroundColor = [UIColor blueColor];
self.tblvLeftPanel.tableHeaderView = self.header;
以下是截图
实际上看起来如何
甚至试过这些方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.hidden = YES;
return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.01f;
}
2个更多截图 身高200 Px
高度300 Px
似乎问题在于自动布局
我已经尝试过这段代码并且正在运行
self.header = [[[NSBundle mainBundle] loadNibNamed:@"LeftMenuHeaderViewViewController" owner:nil options:nil] lastObject];
self.tblvLeftPanel.translatesAutoresizingMaskIntoConstraints = YES;
self.header.frame = CGRectMake(0, 0, 260, 200);
self.header.target = (id)self;
self.header.backgroundColor = [UIColor clearColor];
self.tblvLeftPanel.tableHeaderView = self.header;
但在控制台中获取警告如何解决此问题?
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
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)
(
"<NSAutoresizingMaskLayoutConstraint:0x7fca1ca3f9b0 UITableView:0x7fca1b8fa000.height == 580>",
"<NSLayoutConstraint:0x7fca1c9aa8d0 UIView:0x7fca1c9aa290.bottom == UITableView:0x7fca1b8fa000.bottom>",
"<NSLayoutConstraint:0x7fca1c9aa920 UITableView:0x7fca1b8fa000.top == UIView:0x7fca1c9aa290.top + 20>",
"<NSLayoutConstraint:0x7fca1ca409e0 UIView:0x7fca1c9aa290.height == 568>"
)
Will attempt to recover by breaking constraint
答案 0 :(得分:0)
是的,UiTableView有标题空间,您可以通过拉伸或隐藏在导航栏下隐藏此视图。它的大小通常是64,所以你需要将它拉到顶部才能按照你想要的那样。
答案 1 :(得分:0)
上述约束条件不一致: 1-表底==视图底部 2-桌面高度== 568 3-视图高度== 580 4-视图高度==表高+ 20 这永远无法实现。 IMO的最佳解决方案是删除其中一个约束。哪一个取决于您认为最不重要的。