我是使用UIImagePicker的新品牌,因此請在這裏與我聯繫。基本上,我有兩個UIButton定義訪問相機膠捲,一旦圖像被選中,圖像出現在我的UIImageView中。問題是當我從其中一個按鈕選擇圖像時,它出現在兩個UIImageView中,而不是一個。我基本上希望能夠通過兩個不同的按鈕來選擇兩張不同的照片。這裏是編碼:使用UIImagePicker的多個UIImageViews
-(IBAction)getPhoto1:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popover1 = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover1 presentPopoverFromRect:CGRectMake(0.0, 0.0, 400., 400.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)getPhoto2:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popover2 = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover2 presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
photo1.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
photo2.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
謝謝,這最後工作得很好。我在動作上面設置了一個int:int buttonSelect = 0;然後在不同的動作中將其設置爲1和2,並且效果很好。謝謝! – Taylor
很酷,很高興它爲你工作! – rog