首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个操作的UIActivity

具有多个操作的UIActivity
EN

Stack Overflow用户
提问于 2014-08-14 02:21:16
回答 1查看 140关注 0票数 0

我正在使用几个UIActivity类设置我的应用程序。流程是用户查看一篇文章,然后单击操作按钮来拉出一个UIActivityViewController。

代码语言:javascript
复制
- (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];
}

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

EN

回答 1

Stack Overflow用户

发布于 2014-08-14 03:05:54

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

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

代码语言:javascript
复制
@interface MyViewController : UIViewController <UIAlertViewDelegate>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25293400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档