首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在UIAlertView中传递字典值?

如何在UIAlertView中传递字典值?
EN

Stack Overflow用户
提问于 2013-05-17 12:52:48
回答 3查看 1.6K关注 0票数 0

我有一本字典:

代码语言:javascript
复制
NSMutableDictionary *responseDict = [responseString objectFromJSONString];
代码语言:javascript
复制
{"order_processed":"N","m_fname":"zohaib","m_lname":"sheikh",
"mobile_number":"02343434343","enterd_balance":"610","paid":"Y",
"operator":"Mobilink"}

如何在UIAlertView中显示我的Dict键和值

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-05-17 13:14:13

您可以在从JSON获得响应后将值存储在NSString中,然后可以轻松地在警报视图上显示它们,如下所示:

代码语言:javascript
复制
NSString *testValue1=@"zohaib";
NSString *testValue2=@"999988";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your details" message:[NSString stringWithFormat:@"Name : %@ ,Number : %@",testValue1,testValue2] delegate:self cancelButtonTitle:@"No"  otherButtonTitles:@"Yes", nil];
[alertView setTag:102];
alertView.alertViewStyle =UIAlertViewStyleDefault;
[alertView show];

如果你的意思相同,请让我知道。

票数 0
EN

Stack Overflow用户

发布于 2013-05-17 13:22:08

尝试以下代码:

代码语言:javascript
复制
NSString *str=[NSString stringWithFormat:@"%@ %@ %@",[responseDict valueForKey:@"m_fname"],[responseDict valueForKey:@"m_lname"],[responseDict valueForKey:@"mobile_number"],[responseDict valueForKey:@"enterd_balance"]];

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your details" message:[NSString stringWithFormat:@"%@",str] delegate:self cancelButtonTitle:@"No"  otherButtonTitles:@"Yes", nil];
[alertView show];
票数 1
EN

Stack Overflow用户

发布于 2013-05-17 13:28:51

UIAlertView可能不是显示这类数据的最佳方式。虽然我不知道你的应用程序是做什么的,但我可能会使用UINavigationController来显示客户端列表并点击客户端详细信息( http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/ )。或者,如果我要显示某个操作的结果,我会考虑使用某种自定义的不显眼的视图来显示和清除数据。

原因是UIAlertViews对用户来说非常刺耳。此外,虽然您可以在其中显示大量信息,但它们通常不太适合显示大量数据。

也就是说,要显示UIAlert中的任何文本,必须首先构造一个NSString。下面是使用字典中的两个键的值构造的字符串:

代码语言:javascript
复制
NSString *alertText = [NSString stringWithFormat@"%@ %@", [dictionary valueForKey:@"firstKey"], [dictionary valueForKey:@"secondKey"]];

然后,该字符串将用作UIAlert中的消息或标题:

代码语言:javascript
复制
UIAlert *alert = [[UIAlert alloc] initWithTitle:@"Payment results"
                                        message:alertText
                                       delegate:self
                              cancelButtonTitle:@"Ok"
                              otherButtonTitles:nil
                              otherButtonTitles:nil];

然后调用show来显示警报。请务必阅读UIAlertView documentation,了解其他方法、如何添加其他按钮以及如何响应用户输入。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16601642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档