2011-04-26 80 views
1

如何在不同变量的alertView中显示多条消息?UIAlertView显示多条消息

+0

你是什么意思的多个???请解释你的问题.... – 2011-04-26 07:06:10

+0

你的意思是说多个消息??? – 2011-04-26 07:06:20

+0

喜欢不同的价值和不同的标题。喜欢玩的时间:30;分数:90%。然后显示在不同的行。现在清楚了吗? – 2011-04-26 07:16:33

回答

3

构建从多个变量所需的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]; 
+0

我想在多行显示标题和值。例如...总时间播放:30,总分:90 ...我现在计算的值只需要显示相应的标题with.You现在的想法? – 2011-04-26 07:13:51

+0

您可以将新行字符('\ n')添加到消息字符串中,以便拥有“多行”:http://en.wikipedia.org/wiki/Newline – 2011-04-26 07:16:02

+0

thanks..it's working..i wish if我可以做一个动态的AlertViewController ...任何想法如何做到这一点? – 2011-04-26 07:29:20

1
NSString *[email protected]"total time played:30\n"; 
    NSString *[email protected]"total score :90\n"; 
    NSString *[email protected]"19/2/20010 12:00:77\n"; 
    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]; 
+0

我婉show.time,比分,比赛Finishes.So后correctAns,wrongAns等我需要多和相应values.Please告诉我,我该怎么做,以你的方式 – 2011-04-26 07:13:23

+1

看到我的编辑答案在此向他们展示你可以用单独的行显示你的文字 – Gypsa 2011-04-26 07:20:11

+1

我希望它能适合你! – Gypsa 2011-04-26 07:21:17

0

你不妨割肉出局你的问题多一点,但根据我对你的问题的理解,你应该只能使用

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

UIAlertView构造函数。然后将您的变量连接成一个NSString对象,并将其作为(NSString*)message传递给对象。

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

工厂方法使这个微不足道的。我会推荐reading your options with NSString in the Apple documentation

1
NSString *[email protected]"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];