0

私は、とてもシンプルであるべきだと思われるものにハマってしまったようです!

ユーザーが NSUserDefaults に入力した文字列を電子メールの本文に入力するにはどうすればよいですか?

基本的に、「YES」などの文字列を NSUserDetaults に入力するボタン else ware があります。メール本文をこれらの保存された文字列にするにはどうすればよいですか。

これは私が現在持っているコードです:

- (IBAction)buttonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"SYS"];
[controller setMessageBody:@"How do I make this the content of NSUSERDEFAULTS?" isHTML:NO];
controller.navigationBar.barStyle = UIBarStyleBlack;
[self presentViewController:controller animated:YES completion:nil];

どんな助けでも大歓迎です!

ありがとう!

コードを使用すると、文字列は次のように表示されます: はい、いいえ、たぶん、いいえ、

それらを表示するためにフォーマットを変更するにはどうすればよいですか

はい、

いいえ、

多分、

とんでもない。

お時間をいただきありがとうございます。

4

2 に答える 2

1

\n必要なのは改行文字です。これは(改行)で実現できます。

NSArray *storedStrings = [[NSUserDefaults standardUserDefaults] objectForKey:@"yourStoredKey"];
NSMutableString *messageBody = [NSMutableString string];
for (NSString *aString in storedStrings) {
    [messageBody appendFormat:@"%@,\n\n", aString];
}
[messageBody deleteCharactersInRange:NSMakeRange(messageBody.length-3, 3)];
[controller setMessageBody:messageBody isHTML:NO];

for ループの直後に追加した行は、文字列から最後の 3 文字、つまり 2 つの改行文字とコンマを削除します。

于 2013-04-02T21:35:54.277 に答える
0

この方法を試してください

- (IBAction)buttonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"SYS"];
[controller setMessageBody:[[nsstring stringwithformat@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"yourStoredKey"]]  isHTML:NO];
controller.navigationBar.barStyle = UIBarStyleBlack;
[self presentViewController:controller animated:YES completion:nil];
于 2013-04-03T09:20:18.170 に答える