0

抱歉这个可能很愚蠢的问题,但我无法解决......在我的 ViewController 中,我有一个集合视图,我正在尝试使用 PFRelation 保存单元格的选择。到目前为止一切都很好,但是当我去检查 databrowser Parse 时,我总是只识别一个选定的单元格,我在哪里做错了?错误是我实现 NSIndexPath 的方式吗?

- (IBAction)FFPostSend:(id)sender {
    PFObject *FFSalvaPost = [PFObject objectWithClassName:@"Post"];
    [FFSalvaPost setValue:[PFUser currentUser] forKey:@"Utente"];
    [FFSalvaPost setValue:self.TextView.text forKey:@"Testo"];
    UIImage *image = [self FF_RifimensionaImmagine:self.FF_image ToWidth:(440.0f) andHeight:(500.0f)];
    NSData *imageData = UIImagePNGRepresentation(image);
    PFFile *oggettoFoto =[PFFile fileWithName:@"Immagine.png" data:imageData];
    [FFSalvaPost setObject:oggettoFoto forKey:@"Immagine"];
    PFRelation *relation = [FFSalvaPost relationforKey:@"Scelti"];



    if (FFSwitch.on) {

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0] ;

        [self.FFCollectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];

        if ([[self.FFCollectionView cellForItemAtIndexPath:indexPath] isSelected]) {

            NSLog(@"selected count %i",[self.FFCollectionView indexPathsForSelectedItems].count);

            PFObject *UserSelezionati = [[self.ArrayForUserFoto objectAtIndex:indexPath.item] objectForKey:@"Da_User"];

            [FFSalvaPost setObject:[NSNumber numberWithBool:YES] forKey:@"FLASH_PUSH"];



            [relation addObject:UserSelezionati];
        }


    } else {
        [FFSalvaPost setObject:[NSNumber numberWithBool:NO] forKey:@"FLASH_PUSH"];

    }

    PFACL *acl = [PFACL ACLWithUser:[PFUser currentUser]];
    [acl setPublicReadAccess:YES];
    [FFSalvaPost setACL:acl];

    [FFSalvaPost saveInBackground];

    [self performSelector:@selector(FFConfermaPost) withObject:nil afterDelay:1];


}
4

1 回答 1

1

您只查看第一行:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0] ;

您可以使用UICollectionView.indexPathsForSelectedItems来获取所选项目的 NSIndexPaths 并处理这些。

就像是:

NSArray *indexes = [self.FFCollectionView indexPathsForSelectedItems];
for (NSIndexPath *indexPath in indexes) {   
        PFObject *UserSelezionati = [[self.ArrayForUserFoto objectAtIndex:indexPath.item] objectForKey:@"Da_User"];
        [FFSalvaPost setObject:[NSNumber numberWithBool:YES] forKey:@"FLASH_PUSH"];
        [relation addObject:UserSelezionati];
}

循环内的代码来自您的问题,我没有查看或编辑它。

于 2013-10-31T13:19:26.047 回答