IOS - 如何从解析中检索图像和字符串,并在UICollectionView

时间:2015-11-14 21:21:37

标签: objective-c xcode image parse-platform uicollectionview

好的,我正在使用故事板并尝试添加与图像一起的字符串数据

图像与解析中的图片名称在同一行 我得到了图像并且能够将它放在UICollectionView上我只是在连接同一单元格中的名称时遇到问题 。 如何获得与每个单元格的图像不同的名称

- (void)viewDidLoad {
[super viewDidLoad];
[self queryParseMethod];
self.userCollection.alwaysBounceVertical = YES;
}

- (void)queryParseMethod {
PFQuery *query = [PFQuery queryWithClassName:@"imageandtitle"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (!error) {
        imagefilesArray = [[NSArray alloc] initWithArray:objects];
        [userCollection reloadData];
    }
 }];
}

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

return [imagefilesArray count];
}
-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
userCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"userCard" forIndexPath:indexPath];

PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error)
    {
        self.affiliates = objects;

        for(NSDictionary *affiliate in self.affiliates) {

            //cell.Name.text = affiliate[@"Name"];

            NSArray* array = [[NSArray alloc] initWithObjects:affiliate[@"Name"], nil];
            for (NSString *name in array) {
                PFObject *imageObject = [array objectAtIndex:indexPath.row];

                cell.Name.text = name;

            }
        }
    }
}];
PFObject *imageObject = [imagefilesArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"imageFile"];
PFObject *nameofUser = [imageObject objectForKey:@"Name"];
[imageFile getDataInBackgroundWithBlock:^(NSData * _Nullable data, NSError * _Nullable error) {
    if (!error) {
        cell.userPI.image = [UIImage imageWithData:data];
    }
 }];
return cell;
}

我目前只得到一个名字,如果我试图取消注释另一个cell.text我仍然会得到一个名字,但在所有单元格中。

先谢谢你。

1 个答案:

答案 0 :(得分:0)

抱歉,回答非常简单,我只需要删除for循环和查询,因为我已经查询了一个方法然后输入

cell.Name.text = [imageObject objectForKey:@"Name"];
谢谢你的时间。