我有一个带有自定义单元格的TableView,选中时会显示所选的单选按钮(图像)。一切正常,但是当我开始滚动时,单元格显示不正确(未选中的单选按钮(图像)放在“选定”单元格中)。有谁知道如何解决这个问题?
请查看我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellidentifier = @"ProfileCellReuseIde";
ProfileTableViewCell *cell = (ProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *tempTitle = [tempArr objectAtIndex:indexPath.row];
[cell.titleLblOutlet setText:tempTitle];
cell.radioBtnImgVwOutlet.image = [UIImage imageNamed:@"radio_inactive.png"];
if (indexPath == self.selectedCellIndexPath) {
cell.radioBtnImgVwOutlet.image = [UIImage imageNamed:@"radio_active.png"];
}
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
This works nicely but the only problem I found with this approach is that the user can deselect a row by tapping on it, leaving nothing selected. Simply add the following to prevent this: -(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath { return nil; }
*/
for ( NSIndexPath* selectedIndexPath in tableView.indexPathsForSelectedRows ) {
if ( selectedIndexPath.section == indexPath.section ) {
[tableView deselectRowAtIndexPath:selectedIndexPath animated:NO] ;
ProfileTableViewCell *cell = [tableView cellForRowAtIndexPath:selectedIndexPath];
cell.radioBtnImgVwOutlet.image = [UIImage imageNamed:@"radio_inactive.png"];
}
}
return indexPath ;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath != self.selectedCellIndexPath) {
ProfileTableViewCell *tempPreviousCell = [tableView cellForRowAtIndexPath:self.selectedCellIndexPath];
tempPreviousCell.radioBtnImgVwOutlet.image = [UIImage imageNamed:@"radio_inactive.png"];
self.selectedCellIndexPath = [tableView indexPathForSelectedRow];
ProfileTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.radioBtnImgVwOutlet.image = [UIImage imageNamed:@"radio_active.png"];
}
}
先谢谢。
答案 0 :(得分:2)
在EXECUTE 'UPDATE algorithms.km_cluster_centres_' || quote_literal(k) ||'
SET latitude = ($1).latitude, longitude = ($1).longitude, geom =
ST_Transform(ST_SetSRID(ST_MakePoint(($1).longitude,($1).latitude), 4326),3435)
WHERE id=' || quote_literal( k_count )
USING o_random;
路径中更改if条件。
cellForRowAtIndexPath