我在我的 ViewDidLoad 中试过这个:
NSString *myGrabbedImage = @"myGrabbedImage.png";
NSString *myGrabbedImage2 = @"myGrabbedImage2.png";
NSString *myGrabbedImage3 = @"myGrabbedImage3.png";
NSString *myGrabbedImage4 = @"myGrabbedImage4.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *path2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *path3 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *path4 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *documentDirectory2 = [path2 objectAtIndex:0];
NSString *documentDirectory3 = [path3 objectAtIndex:0];
NSString *documentDirectory4 = [path4 objectAtIndex:0];
NSString *fullPath = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];
NSString *fullPath2 = [documentDirectory2 stringByAppendingPathComponent:myGrabbedImage2];
NSString *fullPath3 = [documentDirectory3 stringByAppendingPathComponent:myGrabbedImage3];
NSString *fullPath4 = [documentDirectory4 stringByAppendingPathComponent:myGrabbedImage3];
NSData *data = [NSData dataWithContentsOfFile:fullPath];
NSData *data2 = [NSData dataWithContentsOfFile:fullPath2];
NSData *data3 = [NSData dataWithContentsOfFile:fullPath3];
NSData *data4 = [NSData dataWithContentsOfFile:fullPath4];
if ([myGrabbedImage isEqualToString:@"myGrabbedImage.png"])
{
[[self firstImageView]setImage:[UIImage imageWithData:data]];
}
else if ([myGrabbedImage2 isEqualToString:@"myGrabbedImage2.png"])
{
[[self secondImageView]setImage:[UIImage imageWithData:data2]];
}
else if ([myGrabbedImage3 isEqualToString:@"myGrabbedImage3.png"])
{
[[self thirdImageView]setImage:[UIImage imageWithData:data3]];
}
else
{
[[self fourthImageView]setImage:[UIImage imageWithData:data4]];
}
然后我在我的 UIImagePickerController 方法中有这个:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image1 = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImagePNGRepresentation(image1);
NSString *myGrabbedImage = @"myGrabbedImage.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];
[data writeToFile:fullPathToFile atomically:YES];
if (picker == imagePickerController)
{
[[self firstImageView]setImage:image1];
}
else if (picker == imagePickerController2)
{
[[self secondImageView]setImage:image1];
}
else if (picker == imagePickerController3)
{
[[self thirdImageView]setImage:image1];
}
else if (picker == imagePickerController4)
{
[[self fourthImageView]setImage:image1];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
粗略地说,ViewDidLoad 只显示一张图像。但是我怎样才能让它加载所有 4 UIImageView´s。
提前致谢