首先写一个自定义的BaseTableViewCell
import “BaseTableViewCell.h”
@implementation BaseTableViewCell
(void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellSize:(CGSize)cellsize
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {}
return self;
}(void)drawRect:(CGRect)rect
{CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);//上分割线,
CGContextSetStrokeColorWithColor(context, ([UIColor clearColor]).CGColor);
CGContextStrokeRect(context, CGRectMake(0, -1, rect.size.width, 1));//下分割线
CGContextSetStrokeColorWithColor(context, ([UIColor colorWithWhite:237.0 / 255.0 alpha:1.0]).CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}(void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];// Configure the view for the selected state
}
@end
然后创建一个要用到的UITabelView
import “ScenicSpotOrderDetailsViewController.h”
@interface ScenicSpotOrderDetailsViewController ()
pragma mark - table view dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//返回多少行的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath {
NSInteger row = indexPath.row;switch (row) {
case 0:
return 251;
break;
default:
break;
}return 108;
}(void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{
}
-(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = indexPath.row;
static NSString *cellIndentifier = @"BaseTableViewCell";
CGSize cellSize = [tableView rectForRowAtIndexPath:indexPath].size;
BaseTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier cellSize:cellSize];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
switch (row) {
case 0:{
break;
}
default:
break;
}
return cell;
}
@end
自己用xib搭建View,再把View add到cell中,简单明了的tabelView就出来了