如何在iOS中删除UITableView的底线 [英] How to remove the bottom line of UITableView in iOS

查看:69
本文介绍了如何在iOS中删除UITableView的底线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我创建一个tableView时,最后一个单元格的底部都会有一行,是否有删除它的方法?我不使用Xib或Storyboard,所以请向我展示代码.非常感谢很多!

Whenever I create a tableView,there will be a line at the bottom of the last cell,is there a method to remove it?I don't use the Xib or Storyboard,so please show me the code.Thank you very much!

对不起,我没有清楚描述情况,这是屏幕截图,在此表视图中有两个部分,最后一个单元格的底部有一行

Sorry I didn't describe the situation clearly,here is the Screenshot,I have two sections in this tableview,and there is a line at the bottom of the last cell

推荐答案

如果仅使用自定义单元格,则解决方案非常简单.

The solution is really easy if you just take a custom cell.

首先将一个单元格拖放到TableView中,然后选择TableView使其成为分隔符,如None like-

Firstly drag and drop a cell in your TableView and then select the TableView to make it's separator as None like-

然后将UITableViewCell的类分配给自定义类.

Then Assign the UITableViewCell's class top the custom one.

在情节提要中的TableViewCell中,获取所需的对象,如标签,图像或任何您需要的对象.现在,确保您在单元格底部使用1 px的UIView.连接插座并添加所需的约束.

In the TableViewCell in storyboard, take your required Objects like Lables, images or whatever you need. Now, make sure you take a UIView of 1 px at the bottom of the cell. Connect the outlets and add the required constrains.

您的自定义类可能看起来像-

Your Custom Class may look like -

CustomTableViewCell.h文件-

CustomTableViewCell.h file-

#import <UIKit/UIKit.h>

@interface CustomTableViewCell : UITableViewCell

@property(nonatomic, strong) IBOutlet UILabel *customTextLabel;
@property(nonatomic, strong) IBOutlet UIView *separatorView;

@end

现在,在视图控制器中,只需在部分的底部行显示或隐藏分隔符即可.

Now in the View Controller, just show or hide the separator at the bottom row of your section.

因此,您的数据源方法可能看起来像-

So, your Datasource methods may look like-

-(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;
}

您应该具有类似-

希望这会有所帮助.

这篇关于如何在iOS中删除UITableView的底线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆