-3

On cameraviewcontrolle.mr I take a picture or movie using UIImagePickerController. On completion, I call back to aanvraagviewcontroller.m.

I want to save the the picture by tapping on send button.

My question comes to this I think, how can I import .m file or take the picture/movie to aanvraagviewcontroller.m (I use Parse.com to save my PFObjects)?

This is cameraviewcontroller.m

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        // A photo was taken/selected!
        self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            // Save the image!
            UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
        }
    }
    else {
        // A video was taken/selected!
        self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            // Save the video!
            if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(self.videoFilePath)) {
                UISaveVideoAtPathToSavedPhotosAlbum(self.videoFilePath, nil, nil, nil);
            }
        }
    }
    [self uploadMessage];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popToRootViewControllerAnimated:YES];}




- (void)uploadMessage {
    NSData *fileData;
    NSString *fileName;
    NSString *fileType;

    if (self.image != nil) {
        UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
        fileData = UIImagePNGRepresentation(newImage);
        fileName = @"image.png";
        fileType = @"image";
    }
    else {
        fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
        fileName = @"video.mov";
        fileType = @"video";
    }

    PFFile *file = [PFFile fileWithName:fileName data:fileData];
    [file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
                                                                message:@"Please try sending your message again."
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
        else {//            onderdeelAanvraag[@"file"] = file;
            //            onderdeelAanvraag[@"fileType"] = fileType;
            //            onderdeelAanvraag[@"recipientIDs"] = self.recipients;
            //

            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
                                                                    message:@"Please try sending your message again."
                                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            }
            else {
                // Everything was successful!
                [self reset];
            }
            //            }];
        }
    }];
}

- (void)reset {
    self.image = nil;
    self.videoFilePath = nil;
    [self.recipients removeAllObjects];
}

- (UIImage *)resizeImage:(UIImage *)image toWidth:(float)width andHeight:(float)height {
    CGSize newSize = CGSizeMake(width, height);
    CGRect newRectangle = CGRectMake(0, 0, width, height);
    UIGraphicsBeginImageContext(newSize);
    [self.image drawInRect:newRectangle];
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return resizedImage;
}

This is aanvraagviewcontroller.m (when send button is pressed, i want to save the picture/movie here);

- (IBAction)verstuurAanvraag:(id)sender {
    NSString *onderdeelOmschrijving  = self.onderdeelOmschrijvingField.text ;
    NSString *autoOmschrijving = self.autoOmschrijvingField.text ;


    if  ([onderdeelOmschrijving length] == 0 ||
         [autoOmschrijving length] == 0)
    {

        UIAlertView *alertView = [[ UIAlertView alloc] initWithTitle:@"Leeg veld" message:@"Vul      de lege velden in" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];

        [alertView show];
    }

    else {

        PFObject *onderdeelAanvraag = [PFObject objectWithClassName:@"Aanvragen"];
        [onderdeelAanvraag setObject:[PFUser currentUser] forKey:@"Aanvrager"];
        onderdeelAanvraag[@"OnderdeelOmschrijving"] = onderdeelOmschrijving;
        onderdeelAanvraag[@"AutoOmschrijving"] = autoOmschrijving;
        NSDate *date = [NSDate date];
        onderdeelAanvraag[@"Datum"] =date;


        onderdeelAanvraag[@"file"] = file;
        onderdeelAanvraag[@"fileType"] = fileType;
        onderdeelAanvraag[@"recipientIDs"] = self.recipients;


        // Get random number between 0 and 999999
        int nummer =  arc4random() % 100000;
        NSLog(@"nieuw nummer %d", nummer);
        [onderdeelAanvraag setObject:[NSNumber numberWithInt:nummer] forKey:@"AanvraagNummer"];


        [onderdeelAanvraag saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:  [error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            }
            else {
                [self performSegueWithIdentifier:@"showRecipients" sender:self];
            }
        }];

    }
}

I SOLVED PASSING UITEXTFIELD TEXT BY THIS ;

I solved passing textfield data passing with the segue method like here ;  
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showRecipients"]){
    OntvangersViewController *controller;
    controller = [segue destinationViewController];
    controller.onderdeelOmschrijvingField = self.onderdeelOmschrijvingField;
    controller.autoOmschrijvingField = self.autoOmschrijvingField;
    controller.image = self.image;
    controller.videoFilePath = self.videoFilePath;
    NSLog(@"videofilepath %@", self.videoFilePath);
    controller.recipients = self.recipients;

}

}

Enzo
  • 23
  • 9
  • 1
    It sounds like you're just trying to [pass data between view controllers](http://stackoverflow.com/search?q=pass+data+between+view+controllers). – CodaFi May 07 '14 at 00:06
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Chuck May 07 '14 at 00:09
  • I want to pass picture/movie back (I know it is actually also data, is there a sample of this also?I didnt understand the other topics you came with). – Enzo May 07 '14 at 01:00

1 Answers1

1

Your question is muddled and confused.

The code in a .m file is not shared with other .m files.

The whole point of the C .h header file is that the header file can be shared, while the implementation (.c, or .m for Objective C) is private, and not shared.

If you want a value to be visible to another class, or another object of the same class, you should define a property in the header file.

If you want to pass a value from one view controller to another, this topic has been covered Ad nauseam here and on other forums. There are at least 2 comments on your post pointing you to other threads covering the topic.

Duncan C
  • 128,072
  • 22
  • 173
  • 272