引用:
Xib使用之TableViewCell.xib中创建多个Cell
#import <UIKit/UIKit.h>
@interface TestTableViewCell : UITableViewCell
+ (instancetype)CellWithTableView:(UITableView *)tableView;
@end
@interface TestTableViewCellOne : UITableViewCell
+ (instancetype)CellWithTableView:(UITableView *)tableView;
@end
#import "TestTableViewCell.h"
@implementation TestTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
+(instancetype)CellWithTableView:(UITableView *)tableView {
static NSString *cellFirst = @"TestTableViewCellID";
TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellFirst];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"TestTableViewCell" owner:nil options:nil] firstObject];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
return nil;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
@implementation TestTableViewCellOne
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
+ (instancetype)CellWithTableView:(UITableView *)tableView{
static NSString *cellSecond = @"TestTableViewCellOneID";
TestTableViewCellOne *cell = [tableView dequeueReusableCellWithIdentifier:cellSecond];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"TestTableViewCell" owner:nil options:nil] objectAtIndex:1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
return nil;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end