0

他のクラスでこのクラスのインスタンスを使用して pdf ファイルの作成を実行し、そのファイルを添付して電子メールで送信する目的で、NSObject のサブクラスを作成しました。これにより、PDF の作成や電子メールのコードの重労働がアプリ全体に複製されるのを防ぐことができます。h ファイルは次のとおりです。

#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>


@interface PBVemailWithAttachment : NSObject <MFMailComposeViewControllerDelegate>

//call to create a new PDF file using UIGraphicsBeginPDFContextToFile with the specifeid width and    
height
- (void)setupPDFDocumentNamed:(NSString*)name Width:(float)width Height:(float)height;

//call to start a new page in an existing PDF document wit the size provided in pageRect.
- (void)beginPDFPageWithRect: (CGRect)pageRect;

//call to add text to the current pdf page given a specific font and font size and drawn a the given      
frame.  returns the frame in whcih the text is drawn in order to allow subsequent calls to position   
additional elements on the page correctly relvant to the previously added text.
- (CGRect)addText:(NSString*)text withFont:(NSString*)font withFrame:(CGRect)frame fontSize:
(float)fontSize;


//call to draw a line on the page with the given frame and in the given color.  Returns the frame of the 
drawn line for positioning subsequent objects on the page.

- (CGRect)addLineWithFrame:(CGRect)frame withColor:(UIColor*)color;

//call to place an image on the page at a specific point.  A CGRect will be created for the image frame    
using the CGpoint and the width and height of the provided image.  Returns the frame Rect of the image  
to popsition subsequent objects on the page.

- (CGRect)addImage:(UIImage*)image atPoint:(CGPoint)point;



//closes the UIGraphics content being used to generate the PDF file

- (void)finishPDF;


-(void)emailFileNameAsAttachment:(NSString *)filename withSubject: (NSString *)subject withMessageBody:   
(NSString *)messageBody withMIMEType: (NSString *)mimeType AttachmentNamed:(NSString *)attachmentName;

@end

問題は .m ファイルにあります。デリゲート メソッドを実装すると、dismissViewControlelrAnimated が目に見えて宣言されたセレクターではないというエラーが表示されます。これは、NSObject をサブクラス化したことが原因であることがわかりました。そのため、これを行う方法についていくつか質問があります。

  1. UIViewConotrller または NSObject をサブクラス化する必要がありますか?
  2. そしておそらくもっと重要なことは、MFMailCompose Delegate をどこに実装するか、このオブジェクトのインスタンスを呼び出してそのメソッドを呼び出して PDF を作成する「重労働」を実行するカスタム オブジェクトまたはクラスで、1 に答える可能性があることです。 ti を添付してメールで送信しますか?

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(
    MFMailComposeResult)結果エラー:(NSError*)エラー{

    [自己却下ViewControllerAnimated:YES完了:nil]; }

4

1 に答える 1