0

我的问题是我有一个带有标签的视图,其中标签上的数据来自网络服务,点击它时应该出现邮箱。简而言之,它是一个 mailLabel。同样,在同一个视图中,我有一个自定义单元格,该单元格也有另一个邮件标签,应该发生同样的事情,但邮件地址将是不同的和动态的。

Q1)我是否只需要包含一种邮件方法来处理。Q2)如果是,那么如何,如果不是,那么程序是什么。我为此使用了第二种方法,并在 cellForRow 中将其称为

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        UITapGestureRecognizer *mgmtMail1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mail1LblTappedForCC:)];

        [cell.managementMemberEmail addGestureRecognizer:mgmtMail1LblGesture];

和方法。

- (void)mail1LblTappedForCC:(id)sender
{
    if ([MFMailComposeViewController canSendMail])
    {

        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setSubject:@""];

        NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];
        [mailer setToRecipients:toRecipients];
        NSString *emailBody = @"";
        [mailer setMessageBody:emailBody isHTML:NO];
        mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
        [self presentViewController:mailer animated:YES completion:nil];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
}

其中 objCCforManagement 是自定义类的对象。

4

1 回答 1

0

您的识别器将如何从

NSArray *toRecipients = [NSArray arrayWithObjects:objCCforManagement.managementMemberEmail.text, nil];

使用recognizer.view 获取您的标签文本或objCCforManagement基于label.text 获取值。label.tag=cellRowIndex或在 cellForRow 方法中将特定标签设置为标签等

代码 - -

cell.managementMemberEmail.tag=indexPath.row;

您的 mail1LblTappedForCC 方法无法找到要作为收件人插入的行值或 objCCforManagement。这就是为什么它显示为空白。

通过将其设置为标签来获取基于行标签的电子邮件。

- (void)mail1LblTappedForCC:(UITapGestureRecognizer*)recognizer
{
    if ([MFMailComposeViewController canSendMail])
    {
        UILabel *labelOnWhichItisClicked=(UILabel*)recognizer.view;
        CustomCellForExhibitorDetailVC *cell=(CustomCellForExhibitorDetailVC*)[managementTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:labelOnWhichItisClicked.tag inSection:0]];

        NSLog(@"mail to is == %@",cell.managementMemberEmail.text);

        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;
        [mailer setSubject:@""];

        NSArray *toRecipients =[NSArray arrayWithObjects:cell.managementMemberEmail.text,nil];

        [mailer setToRecipients:toRecipients];
        NSString *emailBody = @"";
        [mailer setMessageBody:emailBody isHTML:NO];
        mailer.navigationBar.barStyle = UIBarStyleBlackOpaque;
        [self presentViewController:mailer animated:YES completion:nil];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
}
于 2013-08-13T07:32:52.117 回答