2012-08-16 107 views
0

我对Xcode非常陌生,我正在尝试编写一个应用程序,允许用户使用相机,拍摄多张照片,然后允许用户选择他们想要附加到应用内电子邮件的图片。 我收到错误,如:不兼容的指针类型将“UIImagePickerController *”传递给类型为“UIImage *”的参数

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

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

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]; 
    } 
} 
+0

好吧......你到底在哪里得到这些错误? – 2012-08-16 18:46:10

+0

在行[composer addAttachmentData:photoData mimeType:@“image/jpg”fileName:[UIImage imageNamed:theimageView.image]];我得到不兼容的指针类型发送'UIImage *'两次参数类型'NSString *' – user1539154 2012-08-17 13:57:58

+0

在线NSData * photoData = [[UIImageJPEGRepresentation([UIImage imageNamed:@“qwerty.png”],1)alloc] init] ;我没有找到实例方法'-alloc'(返回类型默认为'id')以及未使用变量'photoData'以及在初始化期间存储到'photoData'的值永远不会被读取 – user1539154 2012-08-17 14:03:05

回答

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]; 

“电子邮件” 代替此行:

[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"; 
+0

谢谢许多!!!只是一个简单的问题......这将允许我现在选择多个图像,并将它们附加到我的电子邮件? – user1539154 2012-08-17 19:19:10

+0

@ user1539154很高兴为您提供帮助,如果它对您有帮助,请务必将我的答案标记为正确。这是我帖子旁边的复选标记图标。只要你为每一个多个附件创建新的NSData实例都应该工作。我不确定电子邮件的最大尺寸是多少。 – 2012-08-17 19:21:35

+0

谢谢soo !!!非常好!! – user1539154 2012-08-17 19:58:59

相关问题