当我选择一个 UITableViewCell 并开始滚动到单元格从屏幕上消失的位置时,这些单元格上的分隔符会在它们重新出现在屏幕上时消失。
代表:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell == nil){
if(Type == Scene){
Group *scene = [[appdata getScenes]objectAtIndex:lastRequestedPropertyPosition];
[selectedArray addObject:scene.id];
}else if(Type == Product){
Device *device = [[appdata getDevices]objectAtIndex:lastRequestedPropertyPosition];
[selectedArray addObject:device.id];
}
}else{
[selectedArray addObject:[NSNumber numberWithInt:cell.tag]];
}
}
数据源:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"protoCell" forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"protoCell"];
}
Group *group = [[appdata getScenes] objectAtIndex:indexPath.row];
if(group != nil){
[cell.textLabel setText:group.name];
}
cell.tag = group.id.intValue;
return cell;
}
谁能告诉我这里出了什么问题?
谢谢
编辑 使用它只会使分隔符在选择时消失,而不是仅仅将分隔符保留在那里。
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell == nil){
if(Type == Scene){
Group *scene = [[appdata getScenes]objectAtIndex:lastRequestedPropertyPosition];
[selectedArray addObject:scene.id];
}else if(Type == Product){
Device *device = [[appdata getDevices]objectAtIndex:lastRequestedPropertyPosition];
[selectedArray addObject:device.id];
}
}else{
[selectedArray addObject:[NSNumber numberWithInt:cell.tag]];
}
}
最佳答案
我的问题的原因是我使用蓝色阴影来显示被选中的单元格。然而这个阴影有点太大了。它覆盖了分隔符
关于ios - UITableView 单元格分隔符在被选中时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30258452/