Zeichnen Sie eine Linie in iPhone , Ausnahme

Ich versuche, eine Linie zu ziehen.

Schrieb ich einen code wie unten.

UIColor *currentColor = [UIColor blackColor];

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextMoveToPoint(context, startingPoint.x, startingPoint.y);
CGContextAddLineToPoint(context,endingPoint.x , endingPoint.y);
CGContextStrokePath(context);

aber das zeigt Ausnahme wie folgt

Sat Aug 21 10:47:20 AAA-rrr-Mac-mini.local Test[2147] <Error>: CGContextSetLineWidth: invalid context 0x0
Sat Aug 21 10:47:20 AAA-rrr-Mac-mini.local Test[2147] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
Sat Aug 21 10:47:20 AAA-rrr-Mac-mini.local Test[2147] <Error>: CGContextMoveToPoint: invalid context 0x0
Sat Aug 21 10:47:20 AAA-rrr-Mac-mini.local Test[2147] <Error>: CGContextAddLineToPoint: invalid context 0x0
Sat Aug 21 10:47:20 AAA-rrr-Mac-mini.local Test[2147] <Error>: CGContextDrawPath: invalid context 0x0
Sie haben tatsächlich nicht ein graphics-Kontext. Tun Sie dies innerhalb einer drawRect: oder einige andere zufällige Stelle?
im mit Sie es in meine eigene Funktion mit dem Namen drawLine:(CGPoint )Aus:(CGPoint )
sollten alle Rahmen oder einige Datei-Zeichnung?
Sie sollten immer drawRect: für Zeichnung und verwenden Sie setNeedsDisplay für jede Aktualisierung, die Sie wollte.

InformationsquelleAutor new_programmer | 2010-08-21

Schreibe einen Kommentar