彩票13——设置2_UITableViewCell创建
一、说明
这里主要创建我们的 UITableViewCell (QWMSettingTableViewCell).
更加数据item自动创建我们Cell来满足我们tableview的显示。
二、QWMSettingTableViewCell
2.1 QWMSettingTableViewCell.h
//
// QWMSettingTableViewCell.h
// 03_UIView79_彩票
//
// Created by 杞文明 on 17/8/30.
// Copyright © 2017年 杞文明. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "QWMSettingGroup.h"
#import "QWMSettingItem.h"
#import "QWMSettingArrowItem.h"
#import "QWMSettingSwitchItem.h"
@interface QWMSettingTableViewCell : UITableViewCell
+ (instancetype)cellWithTableView:(UITableView *)tableView;
+ (instancetype)cellWithTableView:(UITableView *)tableView cellStyle:(UITableViewCellStyle)cellStyle;
/**行模型*/
@property(nonatomic,strong)QWMSettingItem *item;
@end
2.2 QWMSettingTableViewCell.m
//
// QWMSettingTableViewCell.m
// 03_UIView79_彩票
//
// Created by 杞文明 on 17/8/30.
// Copyright © 2017年 杞文明. All rights reserved.
//
#import "QWMSettingTableViewCell.h"
@implementation QWMSettingTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
return [self cellWithTableView:tableView cellStyle:UITableViewCellStyleValue1];
}
+(instancetype)cellWithTableView:(UITableView *)tableView cellStyle:(UITableViewCellStyle)cellStyle{
static NSString *ID = @"cell";
QWMSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if(cell==nil){
cell = [[QWMSettingTableViewCell alloc] initWithStyle:cellStyle reuseIdentifier:ID];
}
return cell;
}
-(void)setItem:(QWMSettingItem *)item{
_item = item;
//设置数据
self.imageView.image = item.icon;
self.textLabel.text = item.title;
self.detailTextLabel.text = item.subTitle;
//2.设置右边的视图
[self setupRightView];
}
-(void)setupRightView{
if([ _item isKindOfClass:[QWMSettingArrowItem class] ]){
//右侧是箭头
self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_right"]];
}else if([_item isKindOfClass:[QWMSettingSwitchItem class]]){
// 右侧视图是开关
QWMSettingSwitchItem *swItem = (QWMSettingSwitchItem *)_item;
UISwitch *sw = [[UISwitch alloc]init];
sw.on = swItem.isOn;
self.accessoryView = sw;
}else{
self.accessoryView = nil;
}
}
@end