我得到了以下代码:
调试了一段时间。想不通。
[self.vManager vendorsNearLocation:userLocation block:^(NSArray *vendors, NSError *error)
{
self.vManager.vendors_array = [NSArray arrayWithArray:vendors];
NSLog(@"Vendors array was %d long", [self.vManager.vendors_array count]);
if(vendors && [vendors count])
{
for (id v in vendors)
{
Vendor *aVendor = [[Vendor alloc] initWithAttributes:v];
[self.mapView addAnnotation:aVendor];
[self.vManager.vendor_dict setObject:aVendor
forKey:[aVendor name]];
我希望在该循环中设置字典的值。但是字典总是空的。没有错误或警告,没有任何设置然而数组有值并且我的 map 显示了所有供应商。顺便说一下,vManager 是一个单例,并且 Dictionary 在调用者的 viewDidLoad 方法中被初始化
我做的事情有明显错误吗?
最佳答案
我认为您需要在 SINGLETON 类本身中初始化字典。昨天我尝试了同样的事情并且成功了。
只需创建一个函数并在那里初始化字典,然后在使用该字典之前调用该函数。
一定会成功的。
关于iphone - 在 iOS 方法内部,未设置字典的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13097779/