0

I have an UIView BoardView in which I draw lines. When I push a cell in a table view, I draw a line in BoardView.

When I push the first cell everything is ok, the lines is drawn. Now, if I push a second cell, I would like erase the first line and draw the second line.

I have a boolean to know if I have to draw lines or not.

In a viewController :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if(self.boardView.drawLine) {
        self.boardView.drawLine = NO;
       [self.boardView setNeedsDisplay]; //redisplay the context without lines
    }

    Path * path = [self.grid.sommesPathArray objectAtIndex:indexPath.row];
    [self.boardView drawPath:path];
    self.boardView.drawLine = YES;
    [self.boardView setNeedsDisplay]; // display the context with a line
}

In BoardView.m :

- (void)drawRect:(CGRect)rect {

    if (self.drawLine) {
            for(Line * line in lines)
            [self drawLineWithContext: UIGraphicsGetCurrentContext() andLine:line]; //draw lines
    }

}

My problem is that the lines aren't deleted.

cmii
  • 3,556
  • 8
  • 38
  • 69

1 Answers1

0

try this one when you push or select second cell or any cell..

    [self.boardView.path removeAllObjects];  
    [self.boardView setNeedsDisplay];

or

    [self.grid.sommesPathArray removeAllObjects];    
    [self.boardView setNeedsDisplay];

or just remove all points of UIBezierPath which are used for draw line on your view linke bellow..

[myPath removeAllPoints];
[self setNeedsDisplay];   
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70