我已经添加了一个 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/