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

您的视图控制器需要显式符合要调用的UIAlertViewDelegate协议。- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

在视图控制器的@interface(通常在.h文件中)中,您需要像这样包含委托:

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