Question

My problem is i have a view with a label, wherein, the data on label is coming from web service and on tapping it mail box should appear.In a nutshell it is a mailLabel. Similarly on the same view i have a custom cell which too has another mail label and the same thing should happen,but the mail address will be different and dynamic.

Q1) do i need to include only one method of mail for this to handle. Q2) If yes then how and if no then what is the procedure. i have used a second method for this and called this in cellForRow like

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

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

        [cell.managementMemberEmail addGestureRecognizer:mgmtMail1LblGesture];

and method.

- (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];
    }
}

where objCCforManagement is the object of custom class.

Was it helpful?

Solution

How your recognizer will get the to recipient array from

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

Use recognizer.view to get your label text or get value from objCCforManagement on the basis of label.text. Or particular tag set to label like label.tag=cellRowIndex etc in cellForRow method

Code ----

cell.managementMemberEmail.tag=indexPath.row;

Your mail1LblTappedForCC method is unable to find which row value or objCCforManagement is to be inserted as recipient. thats why it is showing blank.

Get your email on the basis of row tag by setting it to label.

- (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];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top