【问题标题】:can i use NSStrings in alerts in iphone objective c?我可以在 iphone 目标 c 的警报中使用 NSStrings 吗?
【发布时间】:2010-08-12 23:55:19
【问题描述】:

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

@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() 有关。

【问题讨论】:

  • 你在设置text 之后你显示了 UIAlertView。您需要先设置它。
  • 另外,NSLog 不会神奇地让它工作。

标签: iphone objective-c nsstring alerts


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      相关资源
      最近更新 更多