0
我試圖創建一個應用程序,它可以讓您從照片庫導入照片並將它們插入到指定的UIImageView中。我能夠讓它在我的界面中爲其中一個UIImageView工作,但無法分配給第二個UIImageView。從照片庫導入多個圖像到應用程序
如果有人能告訴我我做錯了什麼,我將不勝感激!謝謝! SBB
這裏是我的代碼:
@implementation FlipBook2ViewController
- (IBAction)selectExistingPicture {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (IBAction)selectExistingPicture2 {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error accessing photo library"
message:@"Device does not support a photo library"
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark -
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
感謝您的諮詢!我會測試它! – Sunny
嗯..似乎沒有工作。我有兩個按鈕和兩個ImageViews,當按下相應的按鈕時,它們應該由照片庫中選擇的照片填充。 – Sunny
你做了什麼改變? –