123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // LDClassifyLeftView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/4/28.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDClassifyLeftView.h"
- #import "LDClassifyLeftTableViewCell.h"
- #import "LDCategoryModel.h"
- static NSString *const cellIndentifier = @"classifyLeft";
- @interface LDClassifyLeftView()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic,strong)UITableView *tableView;
- @property (nonatomic,strong)NSIndexPath *indexPath;
- @end
- @implementation LDClassifyLeftView
- {
- NSInteger _index;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor YHColorWithHex:0xF4F4F4];
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI{
- self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.tableView registerClass:[LDClassifyLeftTableViewCell class] forCellReuseIdentifier:cellIndentifier];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.tableFooterView = [[UIView alloc]init];
- self.tableView.showsVerticalScrollIndicator = NO;
- [self addSubview:self.tableView];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- LDClassifyLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
- if (!cell) {
- cell = [[LDClassifyLeftTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
- }
- if ([indexPath isEqual:self.indexPath]) {
- cell.isSelect = YES;
- }else{
- cell.isSelect = NO;
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- LDCategoryModel *model = self.dataArray[indexPath.row];
- cell.title = model.name;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- LDClassifyLeftTableViewCell *formerCell = [tableView cellForRowAtIndexPath:self.indexPath];
- formerCell.isSelect = NO;
- self.indexPath = indexPath;
- LDClassifyLeftTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- cell.isSelect = YES;
- if (self.selectRowBlock) {
- self.selectRowBlock(indexPath.row);
- _index = indexPath.row;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 48;
- }
- - (NSInteger)index{
- return _index;
- }
- - (void)setDataArray:(NSArray *)dataArray{
- _dataArray = dataArray;
- [self.tableView reloadData];
- }
- - (NSIndexPath *)indexPath{
- if (!_indexPath) {
- _indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- }
- return _indexPath;
- }
- @end
|