2013-02-22 4 views
0

Я новичок в Objective-C. Я бы хотел отобразить текущую дату и время в представлении предупреждения.UIAlertView с меткой времени

- (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]; 
     } 
+1

И каков ваш вопрос? – 2013-02-22 05:43:58

ответ

0

Строка предупреждающего сообщения должна быть переделана. Попробуйте это:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Posted" 
message:[NSString stringWithFormat:@"Your Message is posted on: %@", todayString] 
delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
0

Вы можете concate NSString с помощью stringWithFormat: или stringWithString: есть и другие функции, доступные appeding, see doc

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 
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]; 
Смежные вопросы