Black Magic
Black Magic

Reputation: 2766

UITableView cell's seperators disappear when selected

When I select a UITableViewCell and start scrolling to the point where the cells disappear from the screen, the seperators on those cells disappear once they reappear on the screen.

Delegate:

- (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]];
    }
}

Datasource:

- (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;
}

Can anyone tell what went wrong here?

Thanks

EDIT Using this just makes the separator disappear on select instead of just keeping the separator there.

- (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]];
    }
}

Upvotes: 0

Views: 926

Answers (2)

Black Magic
Black Magic

Reputation: 2766

The cause of my issue was the fact I used a blue color shade to show a cell being selected. This shade however was a little too big. It was covering the seperator

Upvotes: 1

aBilal17
aBilal17

Reputation: 3132

In tableView:didSelectRowAtIndexPath, if you send both messages below, the issue is visually resolved (with the probable performance cost).

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

For this to work (for me), deselectRowAtIndexPath:animated: must contain animated:YES. The animation used for reloadRowsAtIndexPaths:withRowAnimation: doesn't matter.

Upvotes: 0

Related Questions