简体   繁体   English

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

[英]can i use NSStrings in alerts in iphone objective c?

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(). 我认为答案可能与NSLog()有关。

You're setting the text property after you show the alert. 显示警报后,您要设置text属性。 When the alert is created, it's probably set to nil . 创建警报后,可能将其设置为nil

you have to declare the variable test before the UIAlertView. 您必须在UIAlertView之前声明变量test。

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 然后从警报中的textBox中获取文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM