帮助在警报视图中添加字符串

发布于 2024-08-05 03:32:35 字数 637 浏览 2 评论 0原文

我有一个相当于我想插入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缱绻入梦 2024-08-12 03:32:35

将您的 message: 参数替换为:

message:[NSString stringWithFormat:@"You scored %@ points", finalScore]

另外,请注意,您的 finalScore 的原始代码使用不带任何参数的字符串格式,这要么是无操作,要么是不安全的(如果它包含% 符号)。您还泄漏了 finalScore 对象。

Replace your message: parameter with:

message:[NSString stringWithFormat:@"You scored %@ points", finalScore]

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 your finalScore object.

鲜血染红嫁衣 2024-08-12 03:32:35

尝试如下操作,并将其作为 message 变量传递给 UIAlertView 的初始化:

NSString* message = [NSString stringWithFormat:@"You scored %@ points",
                              [counter2 text]];

您可能需要根据 [counter2 text] 产生的类型更改有关格式化字符串的一些详细信息,但是,尽管上面的方法应该适用于您将遇到的许多情况。

Try something like the following, and pass it as the message variable to UIAlertView's initialization:

NSString* message = [NSString stringWithFormat:@"You scored %@ points",
                              [counter2 text]];

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.

戴着白色围巾的女孩 2024-08-12 03:32:35

代替:

@"You scored X points"

使用:

[NSString stringWithFormat:@"You scored %@ points", finalScore]

Instead of:

@"You scored X points"

use:

[NSString stringWithFormat:@"You scored %@ points", finalScore]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文