【问题标题】:Converting a UIAlertView text into a UILabel将 UIAlertView 文本转换为 UILabel
【发布时间】:2015-08-04 14:59:18
【问题描述】:

有点奇怪的问题,我知道,但我想知道如何将信息从 UIAlertView 传输到 UILabel。在过去的几个小时里,我一直在尝试自己,但没有运气。我正在使用一些预先存在的代码,所以我很难按照我的步骤来了解它们是如何填充 UIAlertView 的,但是我认为在上面显示正文文本会更容易标签而不是在代码上键入。它还使用 REST API,这是生成数据的方式(根据政治立场生成 4 个不同的实例)。

这是 UIAlertViewCode 的 sn-p

NSData *data = [NSJSONSerialization dataWithJSONObject:result options:0 error:0];

[[[UIAlertView alloc] initWithTitle:@"Response" message:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] 
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];

我还需要其他代码吗??

提前感谢:)

【问题讨论】:

    标签: ios uilabel uialertview


    【解决方案1】:

    将消息存储在变量中,然后重复使用:

    //message
    NSData *data = [NSJSONSerialization dataWithJSONObject:result options:0 error:0];
    NSString *message = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    //UIAlert
    [[[UIAlertView alloc] initWithTitle:@"Response" message:message 
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
    
    //UILabel
    yourLabel.text = message;
    

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多