我可以在 iPhone Objective C 的警报中使用 NSStrings 吗?
我正在尝试制作一个应用程序,用户单击按钮,就会弹出一个警报,其中包含文本字段中的文本。但每当我尝试时,我都会收到空白警报。这是我的代码:
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在显示警报之后设置
text
属性。创建警报时,它可能设置为nil
。You're setting the
text
property after you show the alert. When the alert is created, it's probably set tonil
.您必须在 UIAlertView 之前声明变量 test。
然后您从警报中的文本框中获取文本
you have to declare the variable test before the UIAlertView.
Then you get the text from the textBox in your alert