帮助在警报视图中添加字符串
我有一个相当于我想插入 UIAlertView 内部的文本字段的字符串。
NSString *finalScore = [[NSString alloc] initWithFormat:[counter2 text]];
UIAlertView *myAlertView = [[UIAlertView alloc]
initWithTitle:finalScore
message:@"You scored X points"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[myAlertView show];
[myAlertView release];
我想用字符串“finalScore”中的分数替换“X”,
我知道如何将其与分数一起使用,您只需在消息部分下输入不带引号的字符串名称即可,但我也想要那里的文本和绳子一起。
非常感谢, 追赶
I have a sting that is equal to a text field that i want to insert inside of a UIAlertView.
NSString *finalScore = [[NSString alloc] initWithFormat:[counter2 text]];
UIAlertView *myAlertView = [[UIAlertView alloc]
initWithTitle:finalScore
message:@"You scored X points"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[myAlertView show];
[myAlertView release];
I want to replace"X" with the score from the string "finalScore"
I know how to have it just with the score, you would simple just enter the strings name without quotes under the message section, but i want the the text there too along with the string.
Thanks a bunch,
Chase
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的
message:
参数替换为:另外,请注意,您的
finalScore
的原始代码使用不带任何参数的字符串格式,这要么是无操作,要么是不安全的(如果它包含%
符号)。您还泄漏了finalScore
对象。Replace your
message:
parameter with:Also, note that your original code for
finalScore
uses string formatting without any arguments, which is either a no-op or unsafe (if it contains a%
symbol). You are also leaking yourfinalScore
object.尝试如下操作,并将其作为
message
变量传递给 UIAlertView 的初始化:您可能需要根据
[counter2 text] 产生的类型更改有关格式化字符串的一些详细信息
,但是,尽管上面的方法应该适用于您将遇到的许多情况。Try something like the following, and pass it as the
message
variable to UIAlertView's initialization:You might have to change some details about the formatting string depending on the type that comes out of
[counter2 text]
, however, though the above should work in many of the cases you'll encounter.代替:
使用:
Instead of:
use: