数据未显示在UICollectionviewcell中?

时间:2016-04-04 15:47:15

标签: ios uitableview uicollectionview

我在UICollectionviewcell.my中创建一个UIImageview和两个UILables存储在NSArray和formate中的数据是NSDictionary,键和值。但数据未在UICollectionviewCell中显示。这是我的代码请检查我的代码。

//---- ItemviewController ---//
  mensarrayimages = @[ @{ @"description": @"Mens Fashion",
                      @"articles": @[ @{ @"image": @"SlimFit.jpg" },
                                      @{ @"image": @"Brown.jpg" },
                                      @{ @"image": @"Black.jpg" },
                                      @{ @"image": @"Brown.jpg" },
                                      @{ @"image": @"SlimFit.jpg" },
                                      @{ @"image": @"SlimFit.jpg" },
                                      @{ @"image": @"Brown.jpg" },
                                      @{ @"image": @"Black.jpg" },
                                      @{ @"image": @"Brown.jpg" },
                                      @{ @"image": @"SlimFit.jpg" }
                                      ],
                               @"itemname":  @[ @{ @"name": @"SlimFit"},
                                                @{ @"name": @"BrownSlimFit"},
                                                @{ @"name": @"SlimFit"},
                                                @{ @"name": @"BrownSlimFit"},
                                                @{ @"name": @"SlimFit"},
                                                @{ @"name": @"SlimFit"},
                                                @{ @"name": @"BrownSlimFit"},
                                                @{ @"name": @"SlimFit"},
                                                @{ @"name": @"BrownSlimFit"},
                                                @{ @"name": @"SlimFit"}
                                                ],
                            @"itemprice": @[ @{ @"price": @"1499"},
                                             @{ @"price": @"1599"},
                                             @{ @"price": @"1399"},
                                             @{ @"price": @"1599"},
                                             @{ @"price": @"1499"},
                                             @{ @"price": @"1499"},
                                             @{ @"price": @"1599"},
                                             @{ @"price": @"1399"},
                                             @{ @"price": @"1599"},
                                             @{ @"price": @"1499"}
                                             ],
                            },
];
//---UITableview--///

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [mensarrayimages count];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return [modaldatabase.imagesArray count];
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   // static NSString *cellidentifier =@"cell";


        MensCell *cell = [itemTableview dequeueReusableCellWithIdentifier:@"MensCell"];
        //------ NSDictinary------

         cellData = [mensarrayimages objectAtIndex:[indexPath section]];
         priceData = [mensarrayimages objectAtIndex:[indexPath section]];
         priceData1 = [mensarrayimages objectAtIndex:[indexPath section]];

       //--- NSARRAY---

        NSArray *articleData = [cellData objectForKey:@"articles"];
        NSArray *itemnamedata = [priceData objectForKey:@"itemname"];
        priceArr = [priceData1 objectForKey:@"itemprice"];

       [cell setCollectionData:articleData];
       [cell setCollectionData1:itemnamedata];
       [cell setCollectionData2:priceArr];

       return cell;

}

//------ UICollectionview ---///
//-- CollectionviewController--//

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [self.collectionarray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    CollectionCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell1" forIndexPath:indexPath];

    NSDictionary *cellDataname = [self.collectionarray objectAtIndex:[indexPath row]];
    NSLog(@"%@",cellDataname);
    NSDictionary *cellDataimage = [self.arrayImage objectAtIndex:[indexPath row]];
    NSLog(@"%@",cellDataimage);
    NSDictionary *cellDataprice = [self.arrayprice objectAtIndex:[indexPath row]];
    NSLog(@"%@",cellDataprice);

    cell.ItemImageName.image =[UIImage imageNamed:[NSString stringWithFormat:@"%@",[cellDataimage objectForKey:@"image"]]];
    cell.ItemName.text = [cellDataname objectForKey:@"name"];
    cell.ItemPrice.text = [cellDataprice objectForKey:@"price"];

    return cell;
}

UITableviewcell - > UICollectionviewController - > UICollectionviewCell。

1 个答案:

答案 0 :(得分:0)

This is quite a vague question. However, maybe the UI structure is a little off?

UITableView -> UICollectionViewController -> UICollectionViewCell

That is something I have yet to see someone attempt. From what I can see here, you should backtrack to using a simple UITableView or UICollectionView but not both at the same time. Use either:

UITableViewController -> UITableView -> UITableViewCell

or

UICollectionViewController -> UICollectionView -> UICollectionViewCell

I would suggest going with the first since UITableViews are generally easier to code and maintain