【发布时间】:2014-05-07 05:04:16
【问题描述】:
我有一个绘图板应用程序,我正在尝试通过创建一个可变数组来制作一个撤消按钮,该数组将保存调用触摸开始时创建的图像的保存路径。这是我到目前为止的代码
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
t++;
mainImages = [[NSMutableArray alloc] init];
NSString *imagePath = [NSString stringWithFormat:@"Documents/imagePath%d.png", t];
savePath = [NSHomeDirectory() stringByAppendingPathComponent:imagePath];
[UIImagePNGRepresentation(_mainImage.image) writeToFile:savePath atomically:YES];
[mainImages addObject:savePath];
NSLog(@"t is: %d", t);
NSLog(@"imagePath is: %@", imagePath);
NSLog(@"savePath is: %@", savePath);
NSLog(@"contents of mainImages is: %@", mainImages);
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
}
当我运行它时,我的新路径似乎没有添加到 Mutable 数组中,而是替换了之前保存的路径。这是我的调试控制台读取的内容:
2014-05-06 14:12:20.550 drawingSkills[6709:60b] t is: 1
2014-05-06 14:12:20.553 drawingSkills[6709:60b] imagePath is: Documents/imagePath1.png
2014-05-06 14:12:20.555 drawingSkills[6709:60b] savePath is: /var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath1.png
2014-05-06 14:12:20.557 drawingSkills[6709:60b] contents of mainImages is: (
"/var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath1.png"
)
2014-05-06 14:12:25.482 drawingSkills[6709:60b] t is: 2
2014-05-06 14:12:25.483 drawingSkills[6709:60b] imagePath is: Documents/imagePath2.png
2014-05-06 14:12:25.485 drawingSkills[6709:60b] savePath is: /var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath2.png
2014-05-06 14:12:25.487 drawingSkills[6709:60b] contents of mainImages is: (
"/var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath2.png"
)
2014-05-06 14:19:42.799 drawingSkills[6709:60b] t is: 3
2014-05-06 14:19:42.800 drawingSkills[6709:60b] imagePath is: Documents/imagePath3.png
2014-05-06 14:19:42.802 drawingSkills[6709:60b] savePath is: /var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath3.png
2014-05-06 14:19:42.804 drawingSkills[6709:60b] contents of mainImages is: (
"/var/mobile/Applications/9D3013C2-F275-486C-B1EF-8DAE9A5BEA91/Documents/imagePath3.png"
)
谁能告诉我如何将路径添加到可变数组而不是替换以前的路径?
谢谢。
【问题讨论】:
-
如果您提出其他问题,请确保正确格式化您的代码和/或日志输出。如果您让其他人难以阅读您的内容,您将不会得到很多答案。
标签: objective-c ios7 nsmutablearray