好的,我正在使用故事板并尝试添加与图像一起的字符串数据
图像与解析中的图片名称在同一行 我得到了图像并且能够将它放在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我仍然会得到一个名字,但在所有单元格中。
先谢谢你。
答案 0 :(得分:0)
cell.Name.text = [imageObject objectForKey:@"Name"];
谢谢你的时间。