【问题标题】:UITableView cell's seperators disappear when selectedUITableView 单元格分隔符在选中时消失
【发布时间】:2015-05-15 11:32:35
【问题描述】:

当我选择 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 objective-c uitableview separator


【解决方案1】:

我的问题的原因是我使用蓝色阴影来显示被选中的单元格。然而,这种阴影有点太大了。它覆盖了分隔符

【讨论】:

    【解决方案2】:

    tableView:didSelectRowAtIndexPath 中,如果您同时发送下面的两条消息,问题就会在视觉上得到解决(可能会降低性能成本)。

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    

    为了使这个工作(对我来说),deselectRowAtIndexPath:animated: 必须包含animated:YES。用于reloadRowsAtIndexPaths:withRowAnimation: 的动画无关紧要。

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多