多重行动的UIActivity

时间:2014-08-13 18:21:16

标签: ios mfmailcomposeviewcontroller uiactivityviewcontroller uiactivity

我正在使用一些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];
}

但是,编写电子邮件的方法永远不会被调用。我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

您的视图控制器需要明确遵守UIAlertViewDelegate协议才能调用- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

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

@interface MyViewController : UIViewController <UIAlertViewDelegate>