0

いくつかの UIActivity クラスを使用してアプリをセットアップしています。ユーザーが記事を閲覧し、アクションボタンをクリックしてUIActivityViewControllerを引き上げるという流れです。

- (void)prepareWithActivityItems:(NSArray *)activityItems
{
    UIAlertView* dialog = [[UIAlertView alloc] init];
    [dialog setDelegate:self];
    [dialog setTitle:@"Enter Password"];
    [dialog setMessage:@" "];
    [dialog addButtonWithTitle:@"Cancel"];
    [dialog addButtonWithTitle:@"OK"];
    dialog.tag = 5;

    dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
    [dialog textFieldAtIndex:0].keyboardType = UIKeyboardTypeAlphabet;
    [dialog textFieldAtIndex:0].secureTextEntry = YES;

    CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 0.0);
    [dialog setTransform: moveUp];
    [dialog show];
    [dialog release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {
    }

    if (buttonIndex == 1) {
        UITextField *passwordField = [alertView textFieldAtIndex:0];
        if ([passwordField.text isEqualToString:@"password"]) {
            [self composetheemail];
        }
        else
        {
            UIAlertView *oops = [[UIAlertView alloc]initWithTitle:@"Whoops" message:@"That password is incorrect.  Please try again." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
            [oops show];
            [oops release];
        }
    }
}

-(void)composetheemail {

    self.picker = [[MFMailComposeViewController alloc] init];
    self.picker.mailComposeDelegate = self;

    [self.picker setSubject:@"App Test"];

    // Set up recipients
    NSArray *churchemail = [NSArray arrayWithObject:@"email@gmail.com"];
    [self.picker setToRecipients:churchemail];
    // Fill out the email body text
    NSString *emailBody = @"Sent from the App";
    [self.picker setMessageBody:emailBody isHTML:NO];

    [picker release];
}

ただし、メールを作成するメソッドは呼び出されません。ここで何が間違っていますか?

4

1 に答える 1

0

View Controller を呼び出すには、UIAlertViewDelegateプロトコルに明示的に準拠する必要があり- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndexます。

ビュー コントローラーの @interface (通常は.hファイル内) に、次のようにデリゲートを含める必要があります。

@interface MyViewController : UIViewController <UIAlertViewDelegate>
于 2014-08-13T19:05:53.703 に答える