UIAlertView显示多个消息



如何在我的alertView中显示来自不同变量的多个消息?

从多个变量构建所需的NSString,例如:

NSString *foo;
NSString *bar;
NSString *baz;
// ... set values for foo, bar and baz ...
NSString *myMessage = [NSString stringWithFormat:@"%@ %@ %@", foo, bar, baz];

然后将警报视图设置为使用复合消息myMessage:

NSString *myTitle = @"xyz";
UIAlertView *alert = [[UIAlertView alloc]
                       initWithTitle: myTitle
                       message: myMessage
                       delegate: nil
                       cancelButtonTitle: @"OK"
                       otherButtonTitles: nil];
[alert show];
[alert release];
NSString *string1=@"total time played:30n";
    NSString *string2=@"total score :90n";
    NSString *string3=@"19/2/20010 12:00:77n";
    NSString *string=[NSString stringWithFormat:@"%@%@%@",string1,string2,string3];
    UIAlertView *progressAlert = [[UIAlertView alloc] initWithTitle:@"Hello" message:string delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [progressAlert show];
    [progressAlert release];
NSString *str1=@"Message 1.";
NSString *str2= @"Message 2.";
NSString *str3 = @"Message 3";

NSString *msg=[NSString stringWithFormat:@"%@n%@n%@",str1,str2,str3];

FreeCoinsCustomAlert* alert = [[FreeCoinsCustomAlert alloc] initWithTitle:msg
                                                                  message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

你可能希望让你的问题更充实一点,但从我对你的问题的理解来看,你应该能够使用

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

UIAlertView构造函数。然后将变量连接到单个NSString对象中,并将其作为(NSString*)message传递。

+ (id)stringWithFormat:(NSString *)format, ...

工厂方法使这变得微不足道。我建议你阅读苹果文档中的NSString选项

最新更新