我需要根据来自Web服务的数组长度动态创建uilabel。请看我的网络服务结构。
{"result":"Successful","data":[{"price":"100.00","packs":"Bio Bags","pack_id":"1","products":[{"quantity":"15","image":"1454651885ECOWGBS_03.jpg"},{"quantity":"15","image":"1454652017ECOWGBM_03.jpg"},{"quantity":"15","image":"1454652132ECOWGBL_02.jpg"}]},{"price":"200.00","packs":"Party Pack","pack_id":"2","products":[{"quantity":"50","image":"1454589144USI_6819.jpg"},{"quantity":"50","image":"1454587252ecow240b_01.jpg"},{"quantity":"50","image":"1454499020ecow10rp_01.jpg"}]},{"price":"300.00","packs":"Travel Pack","pack_id":"3","products":[{"quantity":"25","image":"1454589144USI_6819.jpg"},{"quantity":"25","image":"1454588615ecow103crp_01.jpg"},{"quantity":"25","image":"1454588259ecowclam_01.jpg"}]},{"price":"400.00","packs":"Kids Pack","pack_id":"4","products":[{"quantity":"25","image":"1454499251ecow6rp_01.jpg"},{"quantity":"25","image":"1454588417ecow5ct_01.jpg"},{"quantity":"25","image":"1454587802ecow340b_01.jpg"}]}]}
我需要在uilabel和uiimage上设置数量名称和图像以及uicollectionview cell.sometime数量名称可以是3有时它可以是20.现在写我将其添加到stoically。请看下面的代码。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{ [UIApplication sharedApplication] .networkActivityIndicatorVisible = NO; NSArray * dataarray = [[NSJSONSerialization JSONObjectWithData:数据选项:0错误:无] objectForKey:@"数据"];
[packdetail removeAllObjects];
for (NSDictionary *tmp in dataarray)
{
NSMutableDictionary *temp = [NSMutableDictionary new];
[temp setObject:[tmp objectForKey:@"packs"] forKey:@"packs"];
[temp setObject:[tmp objectForKey:@"pack_id"] forKey:@"pack_id"];
[packdetail addObject:temp];
NSArray *productarray = [tmp objectForKey:@"products"];
NSLog(@"products %@", productarray);
for (NSDictionary *product in productarray) {
NSMutableDictionary *temp2 =[NSMutableDictionary new];
[temp2 setObject:[product objectForKey:@"quantity"]forKey:@"quantity"];
NSLog(@"temp2 %@", temp2);
[quantity addObject:temp2];
}
}
if (packdetail)
{
[_subscriptioncollectionview reloadData];
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [packdetail count];
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
SubscriptionCell *cell = (SubscriptionCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.packname.text = [[packdetail objectAtIndex:indexPath.row] objectForKey:@"packs"];
cell.productname.text = [[quantity objectAtIndex:indexPath.row] objectForKey:@"quantity"];
return cell;
}
请给我一些基本想法,这样我就能继续前进。