今天被UITableView給坑了一道,我寫了一個橫向的UITableView
如圖,通過這兩個方法實現需求的觸發事件,但是能同時選中兩個index,
據說UITableView不會管視圖外的indexpath,所以重點來了
自己定義一個indexpath,直接上代碼
NSIndexPath *_selectedIdxPath;
其他的都跟平常的UITableView一樣的,只是初始化cell的時候需要這么做
//這是自定義的cell,按自己的需求來 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"filiter"; FilterChooseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[FilterChooseTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell setImgViewImg:[UIImage imageNamed:_filiterData[indexPath.row]]]; cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
//這是未選中的調用的方法,初始化cell的時候,恢復原狀
[cell DownVideoWitnAnimation:NO];
if (indexPath == _selectedIdxPath)
{
[cell MoveUpVideoWithAnimation:NO];
}
return cell;
}
//選中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { FilterChooseTableViewCell *cell = (FilterChooseTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; [cell MoveUpVideoWithAnimation:YES];
_selectedIdxPath = indexPath;
}
//未選中 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { FilterChooseTableViewCell *cell = (FilterChooseTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; [cell DownVideoWitnAnimation:YES];
}