2012-04-02 84 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