如何在iOS中删除UITableView的底线
每当我创建一个tableView时,最后一个单元格的底部都会有一条线,有没有删除它的方法?我不使用Xib或故事板,所以请给我看代码。非常感谢 对不起,我没有清楚地描述情况,这是屏幕截图,我在这个表视图中有两个部分,在最后一个单元格的底部有一行如何在iOS中删除UITableView的底线,ios,objective-c,uitableview,Ios,Objective C,Uitableview,每当我创建一个tableView时,最后一个单元格的底部都会有一条线,有没有删除它的方法?我不使用Xib或故事板,所以请给我看代码。非常感谢 对不起,我没有清楚地描述情况,这是屏幕截图,我在这个表视图中有两个部分,在最后一个单元格的底部有一行 您可以为UITableView 但我认为默认情况下tableView不会显示任何页脚。 因为你的问题不清楚,你没有提供任何截图或其他任何东西。 使用所需的颜色内容创建自定义视图,然后将其分配给tableView self.tableView.tableFo
您可以为
UITableView
但我认为默认情况下tableView不会显示任何页脚。
因为你的问题不清楚,你没有提供任何截图或其他任何东西。
使用所需的颜色内容创建自定义视图,然后将其分配给tableView
self.tableView.tableFooterView = customFooterView;
或者您可能想隐藏/删除tableViewLineSeparator
有两种最简单的方法可以做到这一点。
为分隔符指定清晰颜色或为分隔符指定无颜色
self.tableView.separatorStyle = UITableViewSeparatorStyleNone;
或
要删除tableview的最后一行,即最后一个分隔符,必须在UIViewDidload中使用以下代码
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
或者,如果要删除特定的单元格分隔符,请使用inside cellForRowAtIndexPath方法
tableView.separatorStyle = UITableViewCellSeparatorStyleDefault;
if (indexPath.section == 1 && indexPath.row == 1)
{
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
如果您只需要一个自定义单元格,那么解决方案非常简单 首先在TableView中拖放一个单元格,然后选择TableView,使其分隔符为None-like- 然后将UITableViewCell的类top指定给自定义类 在故事板的TableViewCell中,获取所需的对象,如标签、图像或任何您需要的对象。现在,请确保在单元底部查看1 px。连接插座并添加所需的约束 您的自定义类可能看起来像- CustomTableViewCell.h文件-
#import <UIKit/UIKit.h>
@interface CustomTableViewCell : UITableViewCell
@property(nonatomic, strong) IBOutlet UILabel *customTextLabel;
@property(nonatomic, strong) IBOutlet UIView *separatorView;
@end
你的前景应该是这样的-
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0){
return 2;
}
else{
return 1;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomTableViewCell *cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"sampleCell"];
if(indexPath.section == 0 && indexPath.row == 1){
cell.separatorView.hidden = YES;
}
else if (indexPath.section == 1 && indexPath.row == 0){
cell.separatorView.hidden = YES;
}
else{
cell.separatorView.hidden = NO;
}
cell.customTextLabel.text = @"Test"; //put whatever you want
return cell;
}
希望这有帮助。请显示屏幕截图。有多少部分?您的问题不清楚。在设计表视图时,通常不会出现这样的行。因此,请提供屏幕截图并稍加说明。我在屏幕截图中没有看到任何额外的行。你在说什么?是的,我试过了,但没用。线还在那里。根据你的截图,你必须为最后一排设定条件。在该条件下,必须使用tableView.separatorStyle=UITableViewSeparatorStyleNone;我照你说的做了,这是我在
cellforrowatinedexpath
方法if(indexPath.section==1&&indexPath.row==1){tableView.separatorStyle=uitableviewcellspeparatorstyle;}
,但结果是每个单元格都被删除了底线。我不知道这个分隔符样式属性是否可以这样使用。@Jeremy请查看我上面编辑的答案。希望这对你有帮助
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0){
return 2;
}
else{
return 1;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomTableViewCell *cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"sampleCell"];
if(indexPath.section == 0 && indexPath.row == 1){
cell.separatorView.hidden = YES;
}
else if (indexPath.section == 1 && indexPath.row == 0){
cell.separatorView.hidden = YES;
}
else{
cell.separatorView.hidden = NO;
}
cell.customTextLabel.text = @"Test"; //put whatever you want
return cell;
}