Ant*_*kov 6 objective-c uitableview separator ios
我需要从特定部分中删除顶部边框形式的第一个单元格,并在特定部分中删除最后一个单元格的底部边框.
我用google搜索解决方案来完成从tableView中隐藏分隔符,但我想避免使用它.
当我在显示单元格时使用分隔符插件时,我找到了解决方案.它适用于两个单元格之间的中间分隔符,但不适用于页眉/页脚和单元格之间的分隔符.
另外,我试图在标题中看到子图层,但由于此视图是由我自己创建的,因此我没有找到分隔符视图.
可能我应该使用标题内的图层?拜托,给我一个线索.
Mih*_*ari 18
要删除第一个分隔符,只需删除tableHeaderView. 你可以这样做viewDidLoad:
tableView.tableHeaderView = UIView()
Run Code Online (Sandbox Code Playgroud)
下面的代码帮助我删除 UITableView 中最后一行的分隔符。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) {
cell.separatorInset.left = cell.bounds.size.width
}
}
Run Code Online (Sandbox Code Playgroud)
在你的ViewDiDLoad
- (void)viewDidLoad {
[super viewDidLoad];
yourTableview.tableFooterView=[[UITableView alloc]initWithFrame:CGRectZero];
}
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsZero;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ( indexPath.row == tableData.count-2 ) {
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, CGRectGetWidth(tableView.bounds));
}
else {
// do nothing
}
}
Run Code Online (Sandbox Code Playgroud)
最终输出是
| 归档时间: |
|
| 查看次数: |
7032 次 |
| 最近记录: |