我通过填充“imageFilesArray”并告诉UICollectionViewCells使用其数据来加载“Rooms”UICollectionView,其中包含登录用户在之前的视图控制器中选择的特定图像:
-(void) retrieveSelectedImagesForRooms
{
//parse query where we search the selectedImage array column and return any entry where the array contains the logged in user objectid
PFQuery *getRooms = [PFQuery queryWithClassName:@"collectionViewData"];
[getRooms whereKey:@"selectedImage" equalTo:[PFUser currentUser].objectId];
[getRooms findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error)
{
imageFilesArray = [[NSArray alloc] initWithArray:objects];
[roomsCollection reloadData];
}
}];
}
下一页必须显示用户为之前选择的房间图像选择的特定灯光。因此,当我选择房间时,我将刚刚选择的行的目标添加到Parse上的新列,名为“clickedRoom”:
-(void)selectedRoom:(PFObject*)object
{
[object addUniqueObject:object.objectId forKey:@"clickedRoom"]; //put object id into clickedRoom column on Parse to save what room you specifically chose so that the light images correspond to only that room
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error){}
else{}
}];
}
- (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self selectedRoom:[imageFilesArray objectAtIndex:indexPath.row]];
[self performSegueWithIdentifier:@"myLights" sender:self];
}
现在,在“灯光”页面中,我只需要在“clickedRoom”列中显示具有所选房间的光照图像。我相信它与我如何检索房间图像的原理相同,但我无法弄清楚我应该查询的内容,例如:
-(void) retrieveCorrespondingImagesForLights
{
PFQuery *getLights = [PFQuery queryWithClassName:@"collectionViewData"];
[getLights whereKey:@"clickedRoom" equalTo:**MY-PREVIOUSLY-SELECTED-ROW**.objectid];
[getLights findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error)
{
imageFilesArray = [[NSArray alloc] initWithArray:objects];
[myLightsCollection reloadData];
}
}];
}
有什么建议吗?!
答案 0 :(得分:1)
retrieveCorrespondingImagesForLights与您的roomsCollection在不同的视图控制器中,对吗?如果是这样,那么您将需要将所选房间的对象ID传递给在[self performSegueWithIdentifier:@"myLights" sender:self];
看看Pass Index Number between UITableView List segue
在您的情况下,您应该向目标视图控制器添加一个属性(我称之为LightsViewController)以捕获对象,或者如果查询需要的话,则为objectId。我会建议这样的事情:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"myLights"]) {
// note that "sender" will be the cell that was selected
UICollectionViewCell *cell = (UICollectionViewCell*)sender;
NSIndexPath *indexPath = [roomsCollection indexPathForCell:cell];
LightsViewController *vc = (LightsViewController*)[segue destinationViewController];
vc.selectedObject = indexPath.row;
}
}
然后,在retrieveCorrespondingImagesForLights:
中PFQuery *getLights = [PFQuery queryWithClassName:@"collectionViewData"];
[getLights whereKey:@"clickedRoom" equalTo:self.selectedObject.objectid];
编辑*
如果您不了解确切的实施细节,那么您似乎正在尝试使用Parse在您的视图控制器之间传递数据,而您更适合在应用中本地执行此操作。也许我误解了你的问题。