How to load photos from photo gallery and store it into application project?

前端 未结 3 1168
独厮守ぢ
独厮守ぢ 2021-02-01 09:13

I\'m working on an application that is almost the same as the sample codes i found here. But the method i want to do is different from the sample codes.
Link: PhotoLocations

3条回答
  •  终归单人心
    2021-02-01 09:49

    - (IBAction)UploadPhoto:(id)sender {
        
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Please Select Your Option"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Gallery",nil];
        
        [actionSheet showInView:self.view];
        
        UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
        
        NSIndexPath *clickedButtonPath = [jobstable indexPathForCell:clickedCell];
        
        isSectionIndex = clickedButtonPath.section;
        isRowIndex     = clickedButtonPath.row;
        
    }
    
    
    -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
        
        
        NSLog(@"From didDismissWithButtonIndex - Selected Option: %@", [actionSheet buttonTitleAtIndex:buttonIndex]);
        
        NSString*image=[actionSheet buttonTitleAtIndex:buttonIndex];
        
        if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {
            
            if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            {
                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device Camera Is Not Working" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                [alert show];
                return;
            }
            else{
                
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.delegate = self;
                picker.allowsEditing = YES;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                
                [self presentViewController:picker animated:YES completion:NULL];
                
            }
        }
        
        else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Gallery"]){
            
            
            UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
            pickerView.allowsEditing = YES;
            pickerView.delegate = self;
            [pickerView setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
            [self presentViewController:pickerView animated:YES completion:nil];
            
        }
        
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage* orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
            
            
            
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:isRowIndex inSection:isSectionIndex];
            
            UITableViewCell *cell = [jobstable cellForRowAtIndexPath:indexPath];
            
            UIImageView *tableIMAGE=(UIImageView *)[cell.contentView viewWithTag:19];
            
            tableIMAGE.image=orginalImage;
            
      answersARRAY[indexPath.row] = [NSString stringWithFormat:@"-1,%@,%@,",answersARRAY[indexPath.row],imageStris];
    
        
            
            [self dismissViewControllerAnimated:YES completion:nil];
            
            
        }
        
        - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
            
            [picker dismissViewControllerAnimated:YES completion:NULL];
        
        }

提交回复
热议问题