NSDictionaries の配列があります。現在、この配列には、簡単にするために 2 つの辞書のみが含まれています。
コードをステップ実行していると、それぞれNSDictionary
が適切に作成され、期待される値が含まれています...次の方法でこの配列 (モデルに入力されています) にアクセスします。
@property (nonatomic, retain) NSMutableArray *sDictionaries;
コントローラーでこのプロパティにアクセスするには、次の方法を使用します。
NSArray *array = [[NSArray alloc]initWithArray:sLocator.sDictionaries]
しかし、内部を見るarray
と、キーのみが含まれており、値は含まれていません(モデルで辞書が作成されたときに既に見たものです)。
NSDictionary
このオブジェクトの配列をモデルからコントローラーに渡す際の助けをいただければ幸いです。
編集:これは、受信したデータを反復処理してNSDictionary
オブジェクトに配置するコードです。
NSMutableArray *arrayOfObjects = [[NSMutableArray alloc]initWithCapacity:0];
sDictionaries = [[NSMutableArray alloc]initWithCapacity:0];
int i = 0;
//iterate through each element, get the string, then add to the array
//I know for this example I am receiving 10 element objects which are NSStrings.
//The first string is the key of the dictionary and the next 4 strings are the values.
//Then all the objects are removed from arrayOfObjects and a new dictionary is made
for(Element *element in nodes)
{
[mArray addObject:[element content]];
if(i%5 != 0)
{
[arrayOfObjects addObject:[element content]];
}
if(i%5 == 0)
{
[idArray addObject:[element content]];
}
if([arrayOfObjects count] >= 4)
{
//Here is where the dictionary is created then added to the array.
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:arrayOfObjects forKey:[idArray lastObject]];
[sDictionaries addObject:dictionary];
[arrayOfObjects removeAllObjects];
}
i++;
}