0
我使用這個設置在NSDisctionary一個鍵的值:EXC壞訪問錯誤,除非值是硬編碼
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded currentcolor: %@", currentColor);
if (currentTool == @"paint") {
NSLog(@"End Paint");
CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];
} else {
NSLog(@"End Pattern");
currentColor = @"1.png";
CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];
}
}
如果我嘗試登錄currentColor的值與EXC壞訪問應用程序崩潰(第3行) 如果我註銷並使用硬編碼值,一切正常。它也適用於if語句的第一部分。我已經檢查過指定currentColor的函數,它正在提供正確的值。如果我在這一點硬編碼currentColor的值,它工作正常。我運行了分析器,並且沒有內存泄漏或問題。我怎麼能跟蹤這個問題呢?
你能證明申報並指定顏色的代碼? – 2012-03-13 20:43:06
如果它與'NSLog'崩潰,那麼它絕對與'NSDictionary'無關。你在哪裏設置currentColor;我敢打賭,你沒有正確保留:) – deanWombourne 2012-03-13 20:44:29
這是因爲'currentColor'已被釋放。提供聲明'currentColor'的代碼,以及將其設置在'touchesEnded:withEvent:'方法之外的位置。 – Jeremy 2012-03-13 20:44:42