【发布时间】:2014-08-13 18:21:16
【问题描述】:
我正在使用一些 UIActivity 类设置我的应用程序。流程是用户查看文章,点击action按钮拉出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];
}
但是,编写电子邮件的方法永远不会被调用。我在这里做错了什么?
【问题讨论】:
-
@mehulpatel 我已经做到了。我将 NSLogs 放入
clickedButtonAtIndex和composetheemail方法中。它显示登录控制台,但实际上并没有拉起 composeviewcontroller。我相信这是由于 UIActivity 以及它是如何使用- (UIViewController *)activityViewController { NSLog(@"TEST3"); return self.picker; }部分设置的 -
记住@mehulpatel 这是一个 UIActivity 类而不是 UIViewController。
标签: ios mfmailcomposeviewcontroller uiactivityviewcontroller uiactivity