【问题标题】:How to retrieve certain images from Parse.com如何从 Parse.com 检索某些图像
【发布时间】:2015-02-28 14:31:41
【问题描述】:

我通过填充“imageFilesArray”并告诉 UICollectionViewCells 使用其数据来加载登录用户在先前视图控制器中选择的特定图像的“房间”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];
    }
}];
}

下一页必须显示用户为之前选择的房间图像选择的特定灯光。 So I add the row's objectid I've just selected to a new column on Parse, called "clickedRoom", when the room is selected:

-(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”列中显示具有所选房间的 objectid 的灯光图像。我相信这与我检索房间图像的原理相同,但我无法弄清楚我应该查询什么,例如:

-(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];
    }
}];

}

有什么建议吗?!

【问题讨论】:

    标签: ios objective-c xcode parse-platform uicollectionviewcell


    【解决方案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 在您的视图控制器之间传递数据,而您更适合在您的应用程序中本地执行此操作。也许我误解了你的问题。

    【讨论】:

    • 我喜欢你对 segue 的想法,我现在已经做到了,谢谢!但是,我的问题仍然存在。 [getLights whereKey:@"clickedRoom" equalTo:*self.selectedObject*.objectid] 中的“equalTo: something.objectId”需要什么;是 PFObject 类型。所以现在我有:PFObject *Object = [***** objectAtIndex:self.selectedObject]; PFQuery *getLights = [PFQuery queryWithClassName:@"collectionViewData"]; [getLights whereKey:@"clickedRoom" equalTo:Object.objectId];但是现在不知道应该放什么数组*****,是不是上一页的rooms数组?
    • 我不确定我是否了解您的数据模型。 parse.com 中的 clickedRoom 列是存储数组还是对象指针?
    • 点击的房间是 Parse 中的一个数组列
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多