に置換され、私は、次の機能を有します。興味深いメモリエラーNSMutableArrayのが私のiPadアプリで一貫
被写体が画面をタップするたびに、点が描画され、このメソッドが呼び出され、点が追加されます。 dots
は、この関数が入っているクラスの先頭にstatic NSMutableArray *dots
と定義されています。何か変わったことが起こっています。配列のすべての要素が置き換えられます。 2個のドットを作り、画面をタップした後、先頭にNSLog
からこの出力を見てください:
before adding, dots = (
)
2012-02-13 23:58:48.159 MoreMost[520:707] adding dot 418.000000 548.000000
2012-02-13 23:58:48.161 MoreMost[520:707] dots is now (
"418.000000 548.000000"
)
2012-02-13 23:58:48.748 MoreMost[520:707] before adding, dots = (
"635.000000 410.000000"
)
2012-02-13 23:58:48.749 MoreMost[520:707] adding dot 635.000000 410.000000
2012-02-13 23:58:48.750 MoreMost[520:707] dots is now (
"635.000000 410.000000",
"635.000000 410.000000"
)
は、アレイ全体が着信元素で置換されている方法を参照してください?どうしてこれなの?そして、いいえ、関数はコードの他の場所で呼び出されていません。ユーザーがスクリーンをタップしてその場所にドットを描くたびに、一度だけ呼び出されます)。
ドットはプログラムのどこにも使用されていないことに注意してください。この機能のみ。
#import "Dot.h"
@implementation Dot
@synthesize tapPosition;
CGRect frame;
UIColor *dotColor;
float radius = 20;
- (id)initWithTapPosition:(CGPoint)pt color:(UIColor *)col {
if(self = [super init]) {
tapPosition = pt;
float topLeftX = pt.x - radius;
float topLeftY = pt.y - radius;
if(topLeftX + (radius*2) >= 1024)
return nil;
if(topLeftY + (radius*2) >= 728)
return nil;
if(topLeftY <= 0 || topLeftX <= 0)
return nil;
frame = CGRectMake(topLeftX, topLeftY, radius*2, radius*2);
dotColor = col;
}
return self;
}
- (id)copyWithZone:(NSZone *)zone
{
Dot *dot = [[[self class] allocWithZone:zone] initWithTapPosition:tapPosition color:dotColor];
return dot;
}
- (CGRect)getFrame {
return frame;
}
- (UIColor *)getColor {
return dotColor;
}
- (NSString *)description {
return [NSString stringWithFormat:@"%f %f",frame.origin.x,frame.origin.y];
}
@end
ヘッダ:
#import <Foundation/Foundation.h>
@interface Dot : NSObject {
@public
CGPoint tapPosition;
}
@property (nonatomic, assign) CGPoint tapPosition;
- (CGRect)getFrame;
- (id)initWithTapPosition:(CGPoint)pt color:(UIColor *)col;
- (UIColor *)getColor;
@end
ドットが使用されている他の場所を表示できますか? –
文字通りどこにいなくても今どこ。 – CodeGuy
ドットクラスはどのように見えますか?彼らはxとyの静的変数を共有していますか? –