<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
//用来记录我们点击的indexpath
@property(nonatomic,assign)NSIndexPath *isSelected;
//创建tableview
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 238, WEIDTH, HEIGHT-235-67) style:UITableViewStylePlain];
_tableView.delegate=self;
_tableView.dataSource=self;
_tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
_tableView.rowHeight=80;
[self.view addSubview:_tableView];
//注册我们自定义的cell
[self.tableView registerClass:[StatusTableViewCell class] forCellReuseIdentifier:NSStringFromClass([StatusTableViewCell class])];
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
StatusTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([StatusTableViewCell class])];
if (indexPath.row==0) {
cell.nameLabel.text=@"";
cell.dataLabel.text=@"";
cell.timeLabel.text=@"";
cell.numberLabel.text=@"";
cell.bgView.backgroundColor=[UIColor colorWithRed:158/255.0 green:222/255.0 blue:89/255.0 alpha:1];
cell.HeadimageView.image=[UIImage imageNamed:@"turang"];
}
if (indexPath.row==1) {
cell.nameLabel.text=@"";
cell.dataLabel.text=@"";
cell.timeLabel.text=@"";
cell.numberLabel.text=@"";
cell.bgView.backgroundColor=[UIColor colorWithRed:245/255.0 green:113/255.0 blue:112/255.0 alpha:1];
cell.HeadimageView.image=[UIImage imageNamed:@"yanfen"];
}
if (indexPath.row==2) {
cell.nameLabel.text=@"";
cell.dataLabel.text=@"";
cell.timeLabel.text=@"";
cell.numberLabel.text=@"";
cell.bgView.backgroundColor=[UIColor colorWithRed:122/255.0 green:179/255.0 blue:249/255.0 alpha:1];
cell.HeadimageView.image=[UIImage imageNamed:@"shuiwexi"];
}
if (indexPath.row==3) {
cell.nameLabel.text=@"";
cell.dataLabel.text=@"";
cell.timeLabel.text=@"";
cell.numberLabel.text=@"";
cell.bgView.backgroundColor=[UIColor colorWithRed:251/255.0 green:175/255.0 blue:82/255.0 alpha:1];
cell.HeadimageView.image=[UIImage imageNamed:@"ph"];
}
return cell;
}
//单选
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//找cell主要可以用来单选
StatusTableViewCell *celled=[tableView cellForRowAtIndexPath:_isSelected];
celled.accessoryType=UITableViewCellAccessoryNone;
StatusTableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType=UITableViewCellAccessoryCheckmark;
self.isSelected=indexPath;
//加上下面的就可以一个都不选,仅仅上面的就会始终有一个
// if (_isSelected==indexPath) {
//
// celled.accessoryType=UITableViewCellAccessoryNone;
// }else{
//
// cell.accessoryType=UITableViewCellAccessoryCheckmark;
// }
}
//多选
//-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// [tableView deselectRowAtIndexPath:indexPath animated:NO];
//
// StatusTableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
// if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { //如果为选中状态
// cell.accessoryType = UITableViewCellAccessoryNone; //切换为未选中
// [_selectIndexs removeObject:indexPath]; //数据移除
// }else { //未选中
// cell.accessoryType = UITableViewCellAccessoryCheckmark; //切换为选中
// [_selectIndexs addObject:indexPath]; //添加索引数据到数组
// } NSLog(@"indexPath==%@",_isSelected);
//}