0

私はObjective-Cの初心者です。アラート ビューに現在の日時を表示したいと考えています。

- (IBAction)postButtonPressed:(UIButton *)sender  {

    NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"MMM d, yyyy h:mm" options:0 locale:[NSLocale currentLocale]];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:formatString];

    NSString *todayString = [dateFormatter stringFromDate:[NSDate date]];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" message:@"Your Message is posted on: @todayString" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alert show];
      }
4

3 に答える 3

0

アラート メッセージ文字列をやり直す必要があります。これを試して:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" 
message:[NSString stringWithFormat:@"Your Message is posted on: %@", todayString] 
delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
于 2013-02-22T05:47:17.317 に答える
0

を使用して連結NSStringするstringWithFormat:stringWithString:、他の追加機能も利用できます。ドキュメントを参照してください

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" message:[NSString stringWithFormat:@"Your Message is posted on: %@",todayString] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release]; //don't forget to release UIAlertView object if you don't using ARC
于 2013-02-22T05:49:45.830 に答える
0

試す

NSString *str = [NSString stringWithFormat:@"Your Message is posted on: %@", todayString];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
于 2013-02-22T05:56:51.890 に答える