2012-08-16 91 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

相關問題