2012-04-02 44 views
0

我有一个非常基本的问题与NSString stringWithFormat。我想要输入用户输入的名称并显示在alertView:Welcome用户名中。无法找出与stringWithFormat的错误

NSString *welcomeMessage = [NSString stringWithFormat:(@"Welcome %@", passedData)]; 
UIAlertView *alert = [[UIAlertView alloc] //show alert box with option to play or exit 
         initWithTitle: welcomeMessage 
         message:@"Once you press \"Play\" the timer will start. Good luck!" 
         delegate:self 
         cancelButtonTitle:@"I want out!" 
         otherButtonTitles:@"Play",nil]; 
[alert show]; 

passedData是已输入的用户名。我目前的方式 - 只有用户名显示在警告框的标题中,而不是“欢迎”部分。我知道我在这里错过了一些真正的基础知识,但会感谢一些帮助。

回答

3

我认为()是不需要的。尝试使用:

NSString *welcomeMessage = [NSString stringWithFormat:@"Welcome %@", passedData]; 

,而不是

NSString *welcomeMessage = [NSString stringWithFormat:(@"Welcome %@", passedData)]; 

希望它可以帮助

+0

它是那样简单,谢谢。 – garethdn 2012-04-02 13:48:47

+0

@garethdn不用客气;) – Novarg 2012-04-02 13:51:10