- 以后所有代碼自定義cell,都可以 直接繼承這個cell。 然后在
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//如下使用就可以了
//ServerDetailHeaderCell *cell = [ServerDetailHeaderCell cellWithTableView:tableView];
// cell.model = self.modelDetail;
// return cell;
}
中直接調(diào)用該Cell的初始化方法。就可以了。
- 下面直接上代碼,不BB了。
//
// LTCell.h
// NSStringTest
//
// Created by Apple on 16/3/24.
// Copyright ? 2016年 wjx. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LTCell : UITableViewCell
/**
* 1.Cell的復(fù)用
*
* @param tableView <#tableView description#>
*
* @return <#return value description#>
*/
+ (instancetype)cellWithTableView:(UITableView*)tableView;
/**
* 2.設(shè)置視圖
*/
- (void)setupUI;
@end
//
// LTCell.m
// NSStringTest
//
// Created by Apple on 16/3/24.
// Copyright ? 2016年 wjx. All rights reserved.
//
#import "LTCell.h"
@implementation LTCell
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
NSString *className = NSStringFromClass([self class]);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:className];
if (cell == nil) {
cell = [[[super class] alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:className];
}
return (LTCell *)cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setupUI];
}
return self;
}
- (void)setupUI
{
[self.contentView setBackgroundColor:[UIColor whiteColor]];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
- (void)layoutSubviews
{
[super layoutSubviews];
// 分割線
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull subView, NSUInteger idx, BOOL * _Nonnull stop) {
// if ([subView isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")]) {
// subView.x = 0;
// subView.width = ScreenWidth;
// subView.height = 0.5;
// [subView setBackgroundColor:[STColor colorLine]];
// }
}];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}