自定义单选的TableView
在TableView
的代理方法里面
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
DFCPlaceOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:[DFCPlaceOrderCell cellIdentify]];
if (_lastIndexPath && _lastIndexPath == indexPath) {
cell.selectImageView.image = [UIImage imageNamed:@"order_booking_selected"];
}else{
cell.selectImageView.image = [UIImage imageNamed:@"order_booking"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSInteger newRow = [indexPath row];
NSInteger oldRow = _lastIndexPath == nil ? -1 : _lastIndexPath.row;
if (newRow != oldRow) {
DFCPlaceOrderCell *cell = [tableView cellForRowAtIndexPath:indexPath];
DFCPlaceOrderCell *OldCell = [tableView cellForRowAtIndexPath:_lastIndexPath];
cell.selectImageView.image = [UIImage imageNamed:@"order_booking_selected"];
OldCell.selectImageView.image = [UIImage imageNamed:@"order_booking"];
_lastIndexPath = indexPath;
}
}
在viewDidLoad
方法里面
self.tbView.frame = CGRectMake(0, 108 , sc_screenSize.width, sc_screenSize.height - 108);
[self.tbView registerClass:[DFCPlaceOrderCell class] forCellReuseIdentifier:[DFCPlaceOrderCell cellIdentify]];
效果图如下