Iphone 在UITableView中隐藏页脚视图
我一直在努力隐藏页脚视图。我的问题是,当我单击按钮时,页脚中有一个按钮。下面将添加一个部分作为最后一个部分,该按钮也将移动到新创建的部分,现在我想在更新部分后将页脚隐藏在表的前一部分中Iphone 在UITableView中隐藏页脚视图,iphone,uitableview,ios5,footer,Iphone,Uitableview,Ios5,Footer,我一直在努力隐藏页脚视图。我的问题是,当我单击按钮时,页脚中有一个按钮。下面将添加一个部分作为最后一个部分,该按钮也将移动到新创建的部分,现在我想在更新部分后将页脚隐藏在表的前一部分中 footerView.hidden = YES 我在按钮操作中使用了它,但它不起作用。这应该可以 tableView.tableFooterView.hidden = YES; 有四种解决方案。他们是, 解决方案1: tableView.sectionHeaderHeight = 0.0; tableView
footerView.hidden = YES
我在按钮操作中使用了它,但它不起作用。这应该可以
tableView.tableFooterView.hidden = YES;
有四种解决方案。他们是, 解决方案1:
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 1.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
解决方案2:
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 1.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
您可以通过界面生成器在“大小”选项卡下设置页脚/页眉高度
解决方案3:
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 1.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
设置内容插入属性
self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);
它用于使顶部和底部接触边缘
解决方案4:
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 1.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
执行以下步骤,根据您的条件设置值。不接受0.0。较低的值应为1.0
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
if(section == 0) {
return 6;
} else {
return 1.0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 5.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
这可以做到
通过实现委托方法
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
不使用自定义视图时,从
tableView:titleForFooterInSection:
返回nil
,从tableView:heightForFooterInSection:
返回0
@property(nonatomic, strong) NSString *footerTitle;
@property(nonatomic, assign) BOOL shouldHideFooter;
Swift 3.0解决方案,该解决方案还删除了上一个单元格和下一个标题之间令人讨厌的1px边框
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return nil
}
参考@J.Hong的答案,Swift4版本(iOS 11.3): 与@Tim Newton答案相比:
- 无需调用
titleForFooterInstition
- 简化
->CGFloat.leastnormalmagnity
(在国际海事组织更快速).leastnonzerominagnity
self.tableView.tableFooterView = nil
Swift 5解决方案:(隐藏部分页脚,您可能需要另一块来去除表页脚)
我不认为您试图隐藏“footerView”,而是该部分的最后一个单元格。我的回答正确地显示了如何隐藏footerview,而不是隐藏footerview。下一节在footerview之后进行。有两种页脚视图:tableFooterView和sectionFooterView。因此产生了混淆…要使其工作,您应该这样做,
-(CGFloat)tableView:(UITableView*)tableView heightforfooterInstitution:(NSInteger)节{[tableView.tableFooterView setHidden:YES];return 1.0f;}
关键点是return 1.0f这不起作用。节页脚没有隐藏,甚至没有降低到0高度。@@Ramshad您应该引用或属性您复制的工作。此外,指定0.00001f将导致高度为零。我必须根据HTTP请求显示/隐藏页脚。如何应用更改?我想,因为您的示例最初是执行的。