如何删除iOS中UITableView的底线
每当我创建一个tableView时,最后一个单元格的底部会有一行,是否有删除它的方法?我不使用Xib或Storyboard,所以请告诉我代码。非常感谢你!
对不起,我没有清楚地描述情况,这里是截图,我在这个tableview中有两个部分,最后一个单元格的底部有一行
如果您只使用自定义单元格,解决方案非常简单。
首先将一个单元格拖放到TableView中,然后选择TableView使它的分隔符为None,如同
然后将UITableViewCell的类分配给自定义类。
在故事板中的TableViewCell中,将您需要的对象(如Lables,图像或任何其他对象)带走。 现在,确保在单元格的底部采用1 px的UIView。 连接sockets并添加所需的约束。
您的自定义类可能看起来像 –
CustomTableViewCell.h文件 –
#import @interface CustomTableViewCell : UITableViewCell @property(nonatomic, strong) IBOutlet UILabel *customTextLabel; @property(nonatomic, strong) IBOutlet UIView *separatorView; @end
现在在View Controller中,只显示或隐藏截面底行的分隔符。
因此,您的数据源方法可能看起来像 –
-(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; }
你应该得到一个前景 –
希望这可以帮助。
您可以为UITableView
设计自己的自定义页脚但我不认为默认情况下tableView显示任何页脚。 由于您的问题不明确,并且您没有提供任何屏幕截图或其他任何内容。 使用所需的颜色内容创建自定义视图,然后将其分配给tableView。
self.tableView.tableFooterView = customFooterView;
或者您可能想隐藏/删除tableView LineSeparator
有两种最简单的方法可以做到这一点。 为分隔符指定一个清晰的颜色或为分隔符指定none。
self.tableView.separatorStyle = UITableViewSeparatorStyleNone;
要么
self.tableView.separatorColor = [UIColor clearColor];
要删除最后一行,即tableview的最后一个分隔符,您必须在UIViewDidload中使用以下代码
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
或者如果要在cellForRowAtIndexPath方法中删除特定的单元格分隔符
tableView.separatorStyle = UITableViewCellSeparatorStyleDefault; if (indexPath.section == 1 && indexPath.row == 1) { tableView.separatorStyle = UITableViewCellSeparatorStyleNone; }