将 UIAlertView 文本转换为 UILabel
Converting a UIAlertView text into a UILabel
有点奇怪的问题,我知道,但我想知道如何将信息从 UIAlertView 传输到 UILabel。在过去的几个小时里,我一直在尝试自己,但没有运气。我正在玩弄一些预先存在的代码,所以我很难按照我的步骤返回它们是如何填充 UIAlertView 的,但是我认为在上面显示正文文本会更容易标签而不是键入代码。它还使用 REST API 生成数据的方式(根据政治立场生成 4 个不同的实例)。
这是 UIAlertViewCode 的片段
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];
我需要任何其他代码吗??
提前致谢:)
将消息存储在一个变量中然后重新使用它:
//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;
有点奇怪的问题,我知道,但我想知道如何将信息从 UIAlertView 传输到 UILabel。在过去的几个小时里,我一直在尝试自己,但没有运气。我正在玩弄一些预先存在的代码,所以我很难按照我的步骤返回它们是如何填充 UIAlertView 的,但是我认为在上面显示正文文本会更容易标签而不是键入代码。它还使用 REST API 生成数据的方式(根据政治立场生成 4 个不同的实例)。
这是 UIAlertViewCode 的片段
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];
我需要任何其他代码吗??
提前致谢:)
将消息存储在一个变量中然后重新使用它:
//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;