编辑: 我发现一个更简单,以避免最后一节和表尾之间的差距的方法就是推行heightForFooterInSection并返回一个很小的值那不是0.这将导致没有任何东西可见。
由于某些原因,返回0不会抑制分组样式表视图中的分节页脚渲染,并且它将尝试渲染单点页脚。有关于此的StackOverflow的其他讨论。
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
我能在什么感觉就像一个稍微哈克的方式做到这一点,但它似乎很好地工作。
我的黑客只是简单地将你想要的实际页脚视图放在包装视图中,帧位置为(0,-1)。
假设您有一个要使用的表格页脚视图,即一个名为MyTableFooterView的类。
在这种情况下,你可以做这样的事情:
//This is the view we will actually add as the table footer
//We make it one point shorter since the content will be shifted up
//one point out of its frame
CGRect footerFrame = CGRectMake(0, 0, self.tableView.width, myFooterHeight-1);
UIView* tableFooterWrapper = [[UIView alloc] initWithFrame:footerFrame];
//This is the view that we are trying to use as a table footer.
//We place it 1 point up inside the wrapper so it overlaps that pesky 1-point separator.
CGRect contentFrame = CGRectMake(0, -1, self.tableView.width, myFooterHeight);
UIView* footerContent = [[MyTableFooterView alloc] initWithFrame:contentFrame];
//Make sure the footer expands width for to other screen sizes
footerContent.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[tableFooterWrapper addSubview:footerContent];
self.tableView.tableFooterView = tableFooterWrapper;
这可靠地工作对我来说。有可能是更习惯的方式,但我还没有遇到过。
正在为'UITableViewStylePlain'使用'UITableView'吗?这将解决您的问题。 – 2014-11-20 16:42:17
@BartekChlebek TableView是UITableViewStylePlain,仍然有tableview分隔符 – scribbler2309 2014-11-20 21:44:52