开发者

Cant set two NSStrings into one UITextView

I want to get

NSString * test1 = @"one";
 NS开发者_C百科String * test2 = @"two";

to my UITextView. I wrote this:

  uitextview.text = (@"%@, %@",test1, test2 );

but the UITextView only gets the second NSString... Why?


You can also do this:

uitextview.text = [NSString stringWithFormat:@"%@, %@", test1, test2];


You're passing a format string into a method that doesn't accept format strings. A better way is to append one string to the other using stringByAppendingString:

uitextview.text = [test1 stringByAppendingString:test2];


You can't just write @"%@ %@" and expect it to be treated as a format string. It's just an ordinary NSString containing some weird characters. To have it used as a format string, you have to pass it to a method or function that will treat it as such. In this case, you want [NSString stringWithFormat:@"%@ %@",test1, test2].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜