Ios 如何根据来自API的数组动态创建uilabel。?

Ios 如何根据来自API的数组动态创建uilabel。?,ios,api,dynamic,uilabel,Ios,Api,Dynamic,Uilabel,我需要根据来自web服务的数组长度动态创建uilabel。请看我的web服务结构 我需要在uilabel和uiimage以及uicollectionview单元格中设置数量名称和图像。有时数量名称可以是3,有时可以是20。现在就写吧,我要坚忍地把它加进去。请看下面我的代码 { [UIApplication sharedApplication].networkActivityIndicatorVisible=否; NSArray*dataarray=[[NSJSONSerialization JS

我需要根据来自web服务的数组长度动态创建uilabel。请看我的web服务结构

我需要在uilabel和uiimage以及uicollectionview单元格中设置数量名称和图像。有时数量名称可以是3,有时可以是20。现在就写吧,我要坚忍地把它加进去。请看下面我的代码

{ [UIApplication sharedApplication].networkActivityIndicatorVisible=否; NSArray*dataarray=[[NSJSONSerialization JSONObjectWithData:数据选项:0错误:无]objectForKey:@“数据”]

只要给我一些基本的想法,我就能继续前进


您的问题不清楚,您希望在哪个位置创建标签?您的标签是否扩展到数组中的内容?我需要将uilabel放置在UICollectionViewCell中我是否应创建for循环并根据数组创建标签>您必须-在单元格中放置uilabel,制作iBullet-在-(NSInteger)中返回数组大小numberOfItemsInSection:-在-(Null UICollectionViewCell*)单元格中为ItemAtIndexPath设置数据数组中的标签文本:
{"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"}]}]}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
[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;

  }