我可以在 iPhone Objective C 的警报中使用 NSStrings 吗?

发布于 2024-09-14 03:34:33 字数 480 浏览 4 评论 0原文

我正在尝试制作一个应用程序,用户单击按钮,就会弹出一个警报,其中包含文本字段中的文本。但每当我尝试时,我都会收到空白警报。这是我的代码:

@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
 UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [someText show];
 [someText release];
 text = textBox1.text;
 label.text = text;
}

我做错了什么,似乎一切都已就位。我认为答案可能与 NSLog() 有关。

I am trying to make an app where the user clicks a button and an alert pops up with the text from a textfield in it. But whenever i try, i just get a blank alert. This is my code:

@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
 UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [someText show];
 [someText release];
 text = textBox1.text;
 label.text = text;
}

what am i doing wrong it seems like everything is in place like it should be. I think the answer might have something to do with NSLog().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

要走就滚别墨迹 2024-09-21 03:34:33

您在显示警报之后设置text 属性。创建警报时,它可能设置为nil

You're setting the text property after you show the alert. When the alert is created, it's probably set to nil.

Bonjour°[大白 2024-09-21 03:34:33

您必须在 UIAlertView 之前声明变量 test。

text = textBox1.text;
UIAlertView *someText = [[UIAlertView alloc] initWithTitle:@"Text from Textbox1" message:text delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[someText show];

然后您从警报中的文本框中获取文本

you have to declare the variable test before the UIAlertView.

text = textBox1.text;
UIAlertView *someText = [[UIAlertView alloc] initWithTitle:@"Text from Textbox1" message:text delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[someText show];

Then you get the text from the textBox in your alert

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