- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath * )indexPath{
UITableViewCell *cell =nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell ==nil) {
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"huicellacce"]];
cell.backgroundColor = [UIColor clearColor];
//cell.selected = YES;
UIImageView *imageViewSepE = [[UIImageView alloc]initWithFrame:CGRectMake(47, 49, 200, 1)];
imageViewSepE.image = [UIImage imageNamed:@"godline"];
[cell.contentView addSubview:imageViewSepE];
}
return cell;
}
b、比较复杂,用到了底层的框架- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割线
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10,1));
}
第五条: 用代码的方式自定制cell,必须写initWithStyle的方法 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { /*** 这里写要添加控件 ***/ } return self; } 【iOS开发TableView】TabelView自定义cell 第一种:通过创建xib文件。 ①首先创建xib文件 ②创建xib文件对应 的模型A,名字与xib文件一样,并继承UITableViewCell类,并实现cellWithTableView的构造方法。 ③在interface builder里更改xib文件默认的类,为第二步创建的模型类。 ④创建数据模型B,并且A中包含数据模型B ⑤A通过懒加载B方法(就是重写B对象的setter方法)将控件赋值。 第二种:代码自定义cell ①新建一个继承UITableViewCell的类,里面拥有frame模型 ②重写initWithStyle:reuseIdentifier:方法(添加所有需要显示的子控件(不需要设置子控件的数据和frame, 子控件要添加到contentView中,还有添加属性设置). ③建立数据模型 ④建立frame模型(拥有数据模型) ⑤重写数据模型对象的setter方法,然后再里面设置控件大小,和cell的高度。 ⑥控制器拥有frame对象数组。出事Cell的时候直接赋值给cell.frame对象就行。 第六条:iOS开发 - 让tableView不能下拉刷新,可以上拉加载 1. 首先遵循代理 UIScrollViewDelegate 2.实现代理方法即可 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (tabelView.contentOffset.y <= 0) { tabelView.bounces = NO; }else { tabelView.bounces = YES; } } 第七条:去除UITableView底部多余行及分割线 self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];转载于:https://www.cnblogs.com/KennyHito/p/6860934.html