ios - 将 UISwitch 添加到 MFMailComposeViewController

标签 ios mfmailcomposeviewcontroller

我已经添加了一个 UISwtich,现在我想知道如何将状态添加到电子邮件中,例如,如果它处于打开状态,我希望它在电子邮件中显示“打开”。目前我有这个。

- (IBAction)sendtoStudentathome:(id)sender {
MFMailComposeViewController *mailContoller = [[MFMailComposeViewController alloc]init];
[mailContoller setMailComposeDelegate:self];
NSString *email = @"admin@blah.co.uk";
NSArray *emailArray = [[NSArray alloc]initWithObjects:email, nil];
NSString *message = [@[_NameofResident.text, _NameofStudent.text, _AppointmentTime.date,     _NextAppointmentTime.date, _Confirmed.text, myswitch]componentsJoinedByString: @"\n"];
[mailContoller setMessageBody:message isHTML:NO];
[mailContoller setToRecipients:emailArray];
[mailContoller setSubject:@"Feedback"];
[self presentViewController:mailContoller animated:YES completion:nil];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self NameofResident] resignFirstResponder];
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}

在邮件中,我有文本字段可以完美地添加到电子邮件中,唯一没有正确添加的是标记为 myswitch 的 UISwitch。

提前致谢。

最佳答案

请引用以下代码,创建一个 NSString 属性,最初将其文本设置为“off”,因为开关的初始状态为关闭,并通过使用开关状态更改文本。

    @property (nonatomic, retain) NSString *strOnOff;

      UISwitch *onoff = [[UISwitch alloc] initWithFrame: CGRectZero];
            onoff.frame = CGRectMake(0,100,100,50);
            strOnOff = @"off";
            [onoff addTarget: self action: @selector(flip:) forControlEvents:UIControlEventValueChanged];
            // Set the desired frame location of onoff here
            [self addSubview: onoff];

-(void)gototest:(UIButton*)sender
{

    MFMailComposeViewController *mailContoller = [[MFMailComposeViewController alloc]init];
    [mailContoller setMailComposeDelegate:self];
    NSString *email = @"admin@blah.co.uk";
    NSArray *emailArray = [[NSArray alloc]initWithObjects:email, nil];
    NSString *message = [NSString stringWithFormat:@"%@",strOnOff];
    [mailContoller setMessageBody:message isHTML:NO];
    [mailContoller setToRecipients:emailArray];
    [mailContoller setSubject:@"Feedback"];
    [delegate presentViewController:mailContoller animated:YES completion:nil];
}

        - (void)flip:(id)sender {
            if (onoff.on)
            {
                strOnOff = @"On";

            }
            else
            {
                strOnOff = @"Off";
            }
        }

关于ios - 将 UISwitch 添加到 MFMailComposeViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24407172/

相关文章:

ios - 快速拉动刷新

html - 如何使用变量更改 HTML 文件的内容?

iphone - 如何在 MFMailComposeViewController 的 MailComposer 工作表中添加 UIImage

ios - iOS-UITableViewCell不会重新加载,直到我选择另一个单元格

ios - 如何设置 UIScrollView 来动态排列内容?

ios - 写入错误的目标地址格式时,MFMailViewComposer 不会返回错误

objective-c - MFMailComposerViewController 通过 UIActivityViewController 错误

objective-c - 邮件和消息 Controller 的奇怪行为 - 预初始化

ios - UITableView 和 UICollectionView 在一行中重用第一行中的集合

ios - 来自一个来源的多个 View 和 UITables,如何填充它们?