/**选中的行*/
@property (nonatomic, assign) NSInteger selectedRow;
/**记录被打开的行号*/
@property (nonatomic, strong) NSMutableArray *open;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RCLog(@"-selectedRow--%zd--indexPath.row)-%zd",self.selectedRow,indexPath.row);
if(!self.selectedRow){
//第一次点击都要加进去
[self.open addObject:[NSString stringWithFormat:@"%zd",indexPath.row]];
}else{
if ([self.open containsObject:[NSString stringWithFormat:@"%zd",indexPath.row]]) {
//包含,说明之前已经点击过,这次点击的跟上一次是一样的,从打开数组中移除
[self.open removeObject:[NSString stringWithFormat:@"%zd",indexPath.row]];
}else{
//不包含,说明这行时第一次点击,直接加进去就可以了
[self.open addObject:[NSString stringWithFormat:@"%zd",indexPath.row]];
}
}
//记录点击的行号
self.selectedRow = indexPath.row;
//刷新点击的行
[self.table reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reusid = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusid];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusid];
}
if ([self.open containsObject:[NSString stringWithFormat:@"%zd",indexPath.row]]) {
//打开之后
cell.textLabel.text = @"快点关上,我要死啦";
}else{
//正常状态下
cell.textLabel.text = @"点击可以打开我噢";
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.open containsObject:[NSString stringWithFormat:@"%zd",indexPath.row]]) {
//打开的时候cell的高度
return 100;
}else{
return 40;
}
}