大家好,感谢您的宝贵时间。我相信我有一个简单的问题。
我正在尝试去除字符串电子邮件正文中的引号(它们似乎来自从字典中获取我的正文)并将其传递给 MailObject ....不幸的是,我一直在我的 * 上收到 SIGBRT finalString 行。
我错过了什么。再次感谢任何帮助。
NSMutableDictionary *my_data = [myMasterOrderList objectAtIndex:[self.tableView indexPathForCell:cell].row];
NSMutableArray *toEmail = [[NSMutableArray alloc] init];
[toEmail addObject:[my_data objectForKey:@"repemail"]];
NSMutableString *toBody = [my_data objectForKey:@"myOrder"];
// [toBody addObject:[my_data objectForKey:@"myOrder"]];
// NSString *finalSting = [[NSString alloc] init];
NSMutableString *finalString = [NSMutableString stringWithFormat:@"%@",[toBody stringByReplacingOccurrencesOfString:@"\"" withString:@"%20"]];
NSLog(@" toBody my_data%@", finalString);
//************* SEND MAIL *************
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:toEmail];
[mailViewController setSubject:@"Sub Goes Here."];
[mailViewController setMessageBody:finalString isHTML:NO];
[self presentModalViewController:mailViewController animated:YES];
最佳答案
我认为问题是这样的:withString:@"%20"
它需要是 withString:@"%%20"
因为 % 字符在NSStrings,要有一个字面的 % 符号,你需要转义它。
我还要指出,如果您不需要 finalString 可变(根据您发布的代码,您不需要),您可以这样做:
NSString *finalString = [toBody stringByReplacingOccurrencesOfString:@"\"" withString:@"%%20"];
关于objective-c - 如何将电子邮件正文动态传递给 MFMailComposeViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490364/