2013-04-01 2 views
0

나는 선을 그리는 UIView BoardView가 있습니다. 테이블 뷰에서 셀을 누르면 BoardView에 선을 그립니다.드로잉에 그려진 선을 지우는 방법은 무엇입니까?

첫 번째 셀을 모두 누르면 OK입니다. 선이 그려집니다. 이제 두 번째 셀을 누르면 첫 번째 줄을 지우고 두 번째 줄을 그립니다.

선을 그릴 지 여부를 알기 위해 부울 값이 있습니다. 의 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 
} 

BoardView.m에서 :

- (void)drawRect:(CGRect)rect { 

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

} 

내 문제는 선이 삭제되지 않습니다 것입니다.

답변

0

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

또는

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

하거나보기에 선 그리기에 사용되는 UIBezierPath의 모든 점을 제거 .. 하나는 밀거나 두 번째 셀 또는 셀을 선택이 시도 린크 벨로우 ..

[myPath removeAllPoints]; 
[self setNeedsDisplay]; 
관련 문제