不兼容的指针类型将“UIImagePickerController *”传递给“UIImage *”类型的参数

时间:2012-08-16 15:45:16

标签: xcode xcode4.3

我是Xcode的新手,我正在尝试编写一个应用程序,允许用户使用相机,拍摄多张照片,然后允许用户选择他们想要附加到的图片 - app电子邮件。 我收到的错误如下:

Incompatible pointer types passing "UIImagePickerController *" to parameter of type "UIImage *"

Instance method '_alloc' not found (return type defaults to 'id')

Incompatible pointer types sending 'UIImage *' to parameter of type 'NSString *'

Unused variable 'photoData'

这是我的代码

// Camera Control

-(void) takePhotoClicked
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

    {
        UIImagePickerController *theimagepicker = [[UIImagePickerController alloc] init];

        theimagepicker.delegate = self;

        theimagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        theimagepicker.mediaTypes = @[(NSString *) kUTTypeImage] ;
        theimagepicker.allowsEditing = NO;
        [self presentModalViewController:theimagepicker animated:YES];
        [theimagepicker release];
        newMedia = YES;

    }
}

// Choose Photo Control

-(void) choosePhotoClicked
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *theimagepicker = [[UIImagePickerController alloc] init];

        theimagepicker.delegate = self;

        theimagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        theimagepicker.mediaTypes = @[(NSString *) kUTTypeImage];
        theimagepicker.allowsEditing = NO;
        [self presentModalViewController:theimagepicker animated:YES];
        // Save image
        UIImageWriteToSavedPhotosAlbum(theimagepicker, self, @selector(theimagepicker:didFinishSavingWithError:contextInfo:), nil);
        NSLog(@"Creating Mail Data!!!");
        NSData *photoData = [[UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1) alloc] init];

        [theimagepicker release];
        newMedia = NO;

    }
}



// Image Delegate Methods

-(void)theimagepickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    [self dismissModalViewControllerAnimated:YES];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

        theimageView.image = image;
        if (newMedia)
            UIImageWriteToSavedPhotosAlbum(image, self, @selector (image:finishedSavingWithError:contextInfo:), nil);


        NSLog(@"Creating Mail Data!!!");
        NSData *photoData = [[UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1) alloc] init];


    }
    else if ([mediaType isEqualToString:(NSString *) kUTTypeMovie])
    {


        // Code here to support video if enabled
    }
}

-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle: @"Save failed"
                              message: @"Failed to save image"
                              delegate: nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
        [alert release];

    }

}

// Email Control
#pragma mark - Open the mail interface
-(IBAction)email
{
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if([MFMailComposeViewController canSendMail])
    {
        //  NSString *custemail = txtCustomerEmail.text;

        //  NSArray *toRecipients = [NSArray arrayWithObject:custemail];
        // [composer setToRecipients:toRecipients];

        [composer setSubject:@"Title Search results:"];

        [composer addAttachmentData:photoData mimeType:@"image/jpg" fileName:[UIImage imageNamed:theimageView.image]];




        // Fill out the email body text
        NSString *emailBody =[NSString stringWithFormat:@"Examiner Name :%@\nExaminer Address :%@\nExaminer City :%@\nExaminer State :%@\nExaminer Zip Code :%@\nExaminer Email Address :%@\nCustomer Name :%@\nCustomer Address :%@\nCustomer City :%@\nCustomer State :%@\nCustomer Zip Code :%@\nCustomer Email Address :%@\nSearch Through Date :%@\nTitle Held By :%@\nProperty Address :%@\nProperty City :%@\nProperty State :%@\nProperty Zip Code :%@\nProperty County : %@\nTitle Search Notes :%@\nMortgage 1 Lender :%@\nMortgage 1 Dated :%@\nMortgage 1 Recorded :%@\nMortgage 1 Amount :%@\nMortgage 1 Book Number :%@\nMortgage 1 Page Number :%@\nMortgage 1 Assignment :%@\nMortgage 1 Additional Info :%@\nMortgage 2 Lender :%@\nMortgage 2 Dated :%@\nMortgage 2 Recorded :%@\nMortgage 2 Amount :%@\nMortgage 2 Book Number :%@\nMortgage 2 Page Number :%@\nMortgage 2 Assignment :%@\nMortgage 2 Additional Info :%@\nMortgage 3 Lender :%@\nMortgage 3 Dated :%@\nMortgage 3 Recorded :%@\nMortgage 3 Amount :%@\nMortgage 3 Book Number :%@\nMortgage 3 Page Number :%@\nMortgage 3 Assignment :%@\nMortgage 3 Additional Info :%@\nLien/Judgement 1 Creditor :%@\nLien/Judgement 1 Type ;%@\nLien/Judgement 1 Dated :%@\nLien/Judgement 1 Recorded :%@\nLien/Judgement 1 Amount :%@\nLien/Judgement 1 Book Number :%@\nLien/Judgement 1 Page Number :%@\nLien/Judgement 1 Notes :%@\nLien/Judgement 2 Creditor :%@\nLien/Judgement 2 Type ;%@\nLien/Judgement 2 Dated :%@\nLien/Judgement 2 Recorded :%@\nLien/Judgement 2 Amount :%@\nLien/Judgement 2 Book Number :%@\nLien/Judgement 2 Page Number :%@\nLien/Judgement 2 Notes :%@\nLien/Judgement 3 Creditor :%@\nLien/Judgement 3 Type ;%@\nLien/Judgement 3 Dated :%@\nLien/Judgement 3 Recorded :%@\nLien/Judgement 3 Amount :%@\nLien/Judgement 3 Book Number :%@\nLien/Judgement 3 Page Number :%@\nLien/Judgement 3 Notes :%@\nProperty Tax ID :%@\nProperty Tax Amount :%@\nHow Often Are Taxes Paid :%@\nNext Payment Due Date :%@\nNext Payment Due Amount :%@\nExaminers' Notes Line 1:%@\nExaminers' Notes Line 2:%@\nExaminers' Notes Line 3:%@\nExaminers' Notes Line 4:%@\nExaminers' Notes Line 5:%@\nExaminers' Notes Line 6:%@\nExaminers' Notes Line 7:%@\nExaminers' Notes Line 8:%@\nExaminers' Notes Line 9:%@\nExaminers' Notes Line 10:%@\nLegal Description Line 1 :%@\nLegal Description Line 2 :%@\nLegal Description Line 3 :%@\nLegal Description Line 4 :%@\nLegal Description Line 5 :%@\nLegal Description Line 6 :%@\nLegal Description Line 7 :%@\nLegal Description Line 8 :%@\nLegal Description Line 9 :%@\nLegal Description Line 10 :%@\nLegal Description Line 11 :%@\nLegal Description Line 12 :%@\nLegal Description Line 13 :%@\nLegal Description Line 14 :%@\nLegal Description Line 15 :%@\nLegal Description Line 16 :%@\nLegal Description Line 17 :%@\nLegal Description Line 18 :%@\nLegal Description Line 19 :%@\nLegal Description Line 20 :%@\nLegal Description Line 21 :%@\nLegal Description Line 22 :%@\nLegal Description Line 23 :%@\nLegal Description Line 24 :%@\nLegal Description Line 25 :%@\nLegal Description Line 26 :%@\nLegal Description Line 27 :%@\nLegal Description Line 28 :%@\nLegal Description Line 29 :%@\nLegal Description Line 30 :%@", txtExaminerName.text, txtExaminerAddress.text, txtExaminerCity.text, txtExaminerState.text, txtExaminerZip.text, txtExaminerEmail.text, txtCustomerName.text, txtCustomerAddress.text, txtCustomerCity.text, txtCustomerState.text, txtCustomerZip.text, txtCustomerEmail.text, txtSearchThroughDate.text, txtTitleHeldBy.text, txtPropertyAddress.text, txtPropertyCity.text, txtPropertyState.text, txtPropertyZip.text, txtTitleSearchNotes.text, txtMtg1LenderName.text, txtMtg1Dated.text, txtMtg1Recorded.text, txtMtg1Amount.text, txtMtg1BookNumber.text, txtMtg1BookNumber.text, txtMtg1PageNumber.text, txtMtg1Assignment.text, txtMtg1AddlInfo.text, txtMtg2LenderName.text, txtMtg2Dated.text, txtMtg2Recorded.text, txtMtg2Amount.text, txtMtg2BookNumber.text, txtMtg2PageNumber.text, txtMtg2Assignment.text, txtMtg2AddlInfo.text, txtMtg3LenderName.text, txtMtg3Dated.text, txtMtg3Recorded.text, txtMtg3Amount.text, txtMtg3BookNumber.text, txtMtg3PageNumber.text, txtMtg3Assignment.text, txtMtg3AddlInfo.text, txtLien1Creditor.text, txtLien1Type.text, txtLien1Dated.text, txtLien1Recorded.text, txtLien1Amount.text, txtLien1BookNumber.text, txtLien1PageNumber.text, txtLien1Notes.text, txtLien2Creditor.text, txtLien2Type.text, txtLien2Dated.text, txtLien2Recorded.text, txtLien2Amount.text, txtLien2BookNumber.text, txtLien2PageNumber.text, txtLien2Notes.text, txtLien3Creditor.text, txtLien3Type.text, txtLien3Dated.text, txtLien3Recorded.text, txtLien3Amount.text, txtLien3BookNumber.text, txtLien3PageNumber.text, txtLien3Notes.text, txtPropertyTaxID.text, txtPropertyTaxAmount.text, txtHowTaxesArePaid.text, txtNextPaymentDueDate.text, txtNextPaymentAmount.text, txt1ExaminersNotes.text, txt2ExaminersNotes.text, txt3ExaminersNotes.text,txt4ExaminersNotes.text, txt5ExaminersNotes.text, txt6ExaminersNotes.text,txt7ExaminersNotes.text, txt8ExaminersNotes.text, txt9ExaminersNotes.text,txt10ExaminersNotes.text, txt1LegalDescription.text, txt2LegalDescription.text, txt3LegalDescription.text, txt4LegalDescription.text, txt5LegalDescription.text, txt6LegalDescription.text, txt7LegalDescription.text, txt8LegalDescription.text, txt9LegalDescription.text, txt10LegalDescription.text, txt11LegalDescription.text, txt12LegalDescription.text, txt13LegalDescription.text, txt14LegalDescription.text, txt15LegalDescription.text, txt16LegalDescription.text, txt17LegalDescription.text, txt18LegalDescription.text, txt19LegalDescription.text, txt20LegalDescription.text, txt21LegalDescription.text, txt22LegalDescription.text, txt23LegalDescription.text, txt24LegalDescription.text, txt25LegalDescription.text, txt26LegalDescription.text, txt27LegalDescription.text, txt28LegalDescription.text, txt29LegalDescription.text, txt30LegalDescription.text];

        //

        [composer setMessageBody:emailBody isHTML:NO];

        composer.modalPresentationStyle = UIModalPresentationPageSheet;

        [self presentModalViewController:composer animated:YES];

        [composer release];
    }
    else
        [composer release];
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    if (error)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error"

                                                        message:[NSString stringWithFormat:@"error %@", [error description]]

                                                       delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];


        [alert show];
        [alert release];

        [self dismissModalViewControllerAnimated:YES];

    }
    else {
        [self dismissModalViewControllerAnimated:YES];
    }
}

1 个答案:

答案 0 :(得分:0)

好的,在方法“choosePhotoClicked”中删除这些行

    UIImageWriteToSavedPhotosAlbum(theimagepicker, self, @selector(theimagepicker:didFinishSavingWithError:contextInfo:), nil);

    NSData *photoData = [[UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1) alloc] init];

然后从“didFinishPicking ...”

中删除此行
    NSData *photoData = [[UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1) alloc] init];

然后在动作“email”中替换此行:

    [composer addAttachmentData:photoData mimeType:@"image/jpg" fileName:[UIImage imageNamed:theimageView.image]];

使用这些行:

    NSData *imageData = UIImageJPEGRepresentation(theimageView.image, 1.0);
    [composer addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"this is a string file name";