我有一本字典:
NSMutableDictionary *responseDict = [responseString objectFromJSONString];{"order_processed":"N","m_fname":"zohaib","m_lname":"sheikh",
"mobile_number":"02343434343","enterd_balance":"610","paid":"Y",
"operator":"Mobilink"}如何在UIAlertView中显示我的Dict键和值
发布于 2013-05-17 13:14:13
您可以在从JSON获得响应后将值存储在NSString中,然后可以轻松地在警报视图上显示它们,如下所示:
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];如果你的意思相同,请让我知道。
发布于 2013-05-17 13:22:08
尝试以下代码:
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];发布于 2013-05-17 13:28:51
UIAlertView可能不是显示这类数据的最佳方式。虽然我不知道你的应用程序是做什么的,但我可能会使用UINavigationController来显示客户端列表并点击客户端详细信息( http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/ )。或者,如果我要显示某个操作的结果,我会考虑使用某种自定义的不显眼的视图来显示和清除数据。
原因是UIAlertViews对用户来说非常刺耳。此外,虽然您可以在其中显示大量信息,但它们通常不太适合显示大量数据。
也就是说,要显示UIAlert中的任何文本,必须首先构造一个NSString。下面是使用字典中的两个键的值构造的字符串:
NSString *alertText = [NSString stringWithFormat@"%@ %@", [dictionary valueForKey:@"firstKey"], [dictionary valueForKey:@"secondKey"]];然后,该字符串将用作UIAlert中的消息或标题:
UIAlert *alert = [[UIAlert alloc] initWithTitle:@"Payment results"
message:alertText
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil
otherButtonTitles:nil];然后调用show来显示警报。请务必阅读UIAlertView documentation,了解其他方法、如何添加其他按钮以及如何响应用户输入。
https://stackoverflow.com/questions/16601642
复制相似问题