【发布时间】:2013-11-30 08:12:46
【问题描述】:
当我在应用程序中收到 XMPP Presence 时,我将其内容添加到 NSMutableDictionary 以将其发送到另一个 ViewController。如果我使用 NSLog 查看这本字典的内容,我可以看到一切正常.但是当我从另一个ViewController 访问这个NSMutableDictionary 时,我找不到JID。其余的东西都存储得很好。
这就是我在存储 XMPP Presence 内容(即 JID 和名称)时所做的事情。
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSString *fromUser = [[presence from]user]; //name of user
NSString *fromUserJID = [NSString stringWithFormat:@"%@",[presence from]] ;
NSLog(@"presence from user JID :- %@", fromUserJID); // This shows the JID.
[_locationDictionary setObject:fromUser forKey:@"fromUser"];
[_locationDictionary setObject:fromUserJID forKey:@"fromJID"];
NSLog(@"locationary dictionary :- %@",_locationDictionary ); // This shows name as well as JID.
// add to array
[_presenceArray addObject:_locationDictionary];
现在,当我尝试在另一个 ViewController 中访问它时,我会这样做:-
NSString *str=view.annotation.title; //This has the name of the user.
NSLog(@"annotation title :- %@", str);
for (NSDictionary *obj in appDelegate.presenceArray)
{
NSString *titleString = [obj objectForKey:@"fromUser"];
if ([str isEqualToString:titleString]) //for the same username I need the JID
{
NSString *jidString = [obj objectForKey:@"fromJID"];
[ dict setObject:jidString forKey:@"jid"]; //dict is NSMutableDictionary
NSLog(@"retrieved jid is :- %@", dict); // THIS IS NULL
【问题讨论】:
-
jidString 有一些价值还是没有?你初始化你的字典了吗?
-
你在哪里初始化你的“dict”?
-
dict 被初始化,在 ViewDidLoad 中
标签: ios nsstring nsmutabledictionary xmppframework