抱歉可能是愚蠢的问题,但我无法解决...在我的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];
}
答案 0 :(得分: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];
}
循环中的代码来自您的问题,我没有查看或编辑它。