我在这个问题上坐了几个小时,现在我已经失明了。 ;-)writeToFile总是与stringByAppendingPathComponent一起崩溃
我有这样的代码在这里:
- (id) initWithImage:(UIImageView*)imageView andPath: (NSString*) path{
[super init];
drawImage = imageView;
imageFilePath = [NSString stringWithString: path];
NSLog(@"fath: %@", imageFilePath);
return self;
}
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(drawImage.image)];
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:@"img.data"];
NSLog(@"path: %@", path);
[imageData writeToFile:path atomically:YES];
此代码的工作,但是当我改变
[imageData writeToFile:path atomically:YES];
到
[imageData writeToFile:imageFilePath atomically:YES];
应用程序崩溃。
但串看起来完全一样:
2011-06-01 10:38:10.178 L3T[3756:207] fath: /Users/max/Library/Application Support/iPhone Simulator/4.3/Applications/A73945CF-9FD0-46E9-A16B-9C0EFC924B0F/Documents/img.data
2011-06-01 10:38:11.864 L3T[3756:207] path: /Users/max/Library/Application Support/iPhone Simulator/4.3/Applications/A73945CF-9FD0-46E9-A16B-9C0EFC924B0F/Documents/img.data
我只是不明白了!
imageFilePath的定义在哪里?它是你班级中的一员吗? imageFilePath何时分配并初始化? – 2011-06-01 08:48:53