【发布时间】:2016-05-08 03:01:18
【问题描述】:
编辑:
现在删除自动布局后,它仅适用于 iPhone 4,4s 等较小的设备,但不适用于 iPhone 6 iOS 9.1.2。如果我添加一个高度为 80 的空白部分标题,它可以在 iPhone 6 中使用。仍然想知道可能是什么问题?
原问题: 我创建了一个 UIView 子类并为它创建了一个笔尖。 我已将它分配给我的 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 像素
高度 300 像素
似乎问题出在自动布局上
我已经尝试过这段代码,它正在工作
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
【问题讨论】:
-
你是否开启了自动布局?
-
是的,我正在使用尺码等级。我也在 ViewDidLoad self.automaticallyAdjustsScrollViewInsets = NO;
-
那么这很可能是一个自动布局工件。你能提供你所做的所有 AL 设置吗?
-
在 viewForHeaderInSection 方法中返回 nil
-
返回 nil 不起作用
标签: ios objective-c uitableview margin