NSMutableDictionary打印数据的问题

发布于 2024-10-21 16:36:02 字数 552 浏览 0 评论 0原文

我的 NSMutableDictionary 有问题,我想打印字典中的所有键。
我试过了。

for(id theKey in myDict) {
   NSLog(@"Key:%@-Value:%@",theKey,[myDict objectForKey:theKey]);
}

上面的代码可以工作。但我从另一个控制器获取 NSMutableDict 。在该控制器中它有数据。但在新控制器中它是空的。 伙计们帮忙吗? ... :]
@KennyTM:代码在这里:

NewViewController *newCont = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newCont.myDict = [myDict retain];
[self.navigationController pushViewController:newCont animated:YES];
[sign release];

I have a problem with NSMutableDictionary I want to print all the keys in the dictionary.
I tried this.

for(id theKey in myDict) {
   NSLog(@"Key:%@-Value:%@",theKey,[myDict objectForKey:theKey]);
}

The above code is working. But i am getting the NSMutableDict from another controller. In that controller it has Data.But in new controller it is empty.
Guys Help? ... :]
@KennyTM:The code is here:

NewViewController *newCont = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newCont.myDict = [myDict retain];
[self.navigationController pushViewController:newCont animated:YES];
[sign release];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说好的呢 2024-10-28 16:36:02

你的代码没问题。如果您在日志中看不到任何内容,则字典可能为空。您可以使用 -count 方法

if ([myDict count]==0) {
  // empty
} else {
  ...
}

Your code is fine. If you can't see anything in the log, it is possible that the dictionary is empty. You could check if a collection is empty using the -count method.

if ([myDict count]==0) {
  // empty
} else {
  ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文