だから私はアプリケーションに取り組んでおり、自動参照カウントを使用していないので、独自のメモリ管理を行う必要があります。最初のメソッドで UIView のレイヤーに値を設定するこのコードがあります。次に、2 番目の方法でそれを取得します。array1 は私の中で定義されていますviewDidLoad
これが私の最初の方法です
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGFloat endLocation = [touch locationInView:self];
CGRect rect = CGRectMake(startLocation.x, startLocation.y, endLocation.x, endLocation.y);
UIView *rectstring = [[UIView alloc]initWithFrame:rect];
NSString *string = [NSString stringWithFormat:@"%d",pencilbool];
[[rectstring layer] setValue:string forKey:@"color"];
NSString *string1 = [NSString stringWithFormat:@"%f",stepper.value];
[[rectstring layer] setValue:string1 forKey:@"size234"];
[array1 addObject:rectstring];
[rectstring release];
[string release];
[string1 release];
}
2 番目の方法:
-(IBAction)secondmethod {
for (UIView *string1 in array1) {
CGContextRef gc=UIGraphicGetCurrentContext();
CGFloat width =[[string1.layer valueForKey:@"size234"] floatValue];
CGContextSetLineWidth (gc, width);
CGRect rect = [string1 frame];
CGContextMoveToPoint(gc, rect.origin.x, rect.origin.y);
CGContextAddLineToPoint(gc, rect.size.width, rect.size.height);
CGContextStrokePath(gc);
}
}
これにより、 でエラーが発生しCGFloat width =[[string1.layer valueForKey:@"size234"] floatValue];
ます。ただし、最初のメソッドでリリース呼び出しを削除すると:
[string release];
[string1 release];
それはうまくいきます。
なぜこれがエラーを引き起こしているのですか? 何か案は?