2011-06-02 32 views
0

好吧,這是我的問題。NSString全局變量的簡單問題 - 幫助

我有兩個全局的NSString變量。

globalVariable1 //stores one string. 
globalVariable2 //stores 3 strings 

globalVariable2使用

[NSString stringWithFormat:@"%@, %@, %@", Item1, Item2, Item3]; 

我分配

[textField setText:globalVariable1] //NO ERROR // 

[textField setText:globalVariable2] // ERROR // 

誰能告訴我是怎麼回事連接起來?

+2

你能展示更多代碼嗎?什麼類型是globalVariable1,2,初始化在哪裏? – Andrew 2011-06-02 17:12:27

+0

保留了訣竅:) – Legolas 2011-06-02 17:15:45

回答

2

您可能並未保留globalVariable2。由於stringWithFormat:方法將返回一個自動釋放對象,因此您需要在分配它之後保留它。

+0

你是男人。 – Legolas 2011-06-02 17:15:00