我真的很陌生,如果這是一個非常簡單的問題,我很抱歉。我試圖編寫一個代碼來使用UIImagePickerController
從我的圖像庫中選擇兩個不同的圖像,並將其放入兩個UIImageView
s。然後,點擊一個按鈕將圖像上傳到Parse。對兩個ImageViews使用UIImagePickerController並上傳到解析
我有困難使用UIImagePickerController
兩次,我似乎無法在任何地方找到答案。另外,我無法將其鏈接到上傳代碼。我只學過如何上傳已經在文件夾中的文件,但我似乎無法解決如何將其鏈接到UIImagePickerController
。如果你能提供幫助,將會非常感激。到目前爲止我的代碼...
- (IBAction)choosePhotoA:(id)sender {
UIImagePickerController *imagePickerControllerA = [[UIImagePickerController alloc] init];
imagePickerControllerA.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerControllerA.delegate =self;
imagePickerControllerA.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerControllerA animated:NO completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *imageA = [info valueForKey:UIImagePickerControllerOriginalImage];
self.imageViewA.image = imageA;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)uploadPhotoA:(id)sender {
PFObject *newImage = [PFObject objectWithClassName:@"photos"];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"newImage.png"]);
PFFile *newImageFile = [PFFile fileWithName:@"testPhoto.png" data:imageData];
[newImage setObject:newImageFile forKey:@"photoUploadOne"];
[newImage saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error){
NSLog(@"upload success!");
}
}];
}
爲了區分照片A和照片B,您可以使用BOOL狀態屬性,或者驗證imageViewA.image!= nil是否傳遞給imageViewB。它應該做到您choosePhotoA方法集中所有 –
非常感謝你的幫助! – user3193423