с этим кодом, я хочу добавить изображение в том месте, где пользователь нажимает. Я хочу добавить новый для каждого крана.
-(void) foundDoubleTap:(UITapGestureRecognizer *) recognizer
{
UIView *piece = recognizer.view;
CGPoint locationInView = [recognizer locationInView:piece];
UIImageView *testPoint = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"inner-circle.png"]];
testPoint.frame = CGRectMake(0, 0, 20, 20);
testPoint.center = CGPointMake(locationInView.x, locationInView.y);
[self.imageView addSubview:testPoint];
NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];
[tempTestPointArray addObject:testPoint];
testPointArray = tempTestPointArray;
NSLog(@"testPointArray: %@", testPointArray);
CGRect myRect = CGRectMake((testPoint.center.x + 12), (testPoint.center.y + 12), 10, 10);
UILabel *myLabel = [[UILabel alloc] initWithFrame:myRect];
myLabel.text = [NSString stringWithFormat:@"Point %d", [testPointArray count]];
myLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:10];
[myLabel sizeToFit];
[imageView addSubview:myLabel];
[myLabel release];
[testPoint release];
//[tempTestPointArray release];
}
почему, когда я выпускаю tempTestPointArray, мой код ломается, когда я реализую второй тап? он падает на:
NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];
когда я комментирую релиз для него, анализатор не помечает его как утечку. что случилось с правилом, если вы распределяете / инициализируете его, вы должны освободить его?
РЕДАКТИРОВАТЬ: добавление .h файла
.h файл:
@interface TestPointMapViewController : UIViewController <UIScrollViewDelegate, UITextFieldDelegate>
{
//other code
NSArray *testPointArray;
}
//other code
@property (nonatomic, retain) NSArray *testPointArray;
//other code
@end
, а затем @synthesize testPointArray в файле .m.