gpt4 book ai didi

ios - UiCollectionView 在保存对象时没有选择正确的单元格 Parse.com

转载 作者:行者123 更新时间:2023-11-29 03:31:38 25 4
gpt4 key购买 nike

很抱歉这个可能很愚蠢的问题,但我无法解决...在我的 ViewController 中,我有一个 Collection View ,我正在尝试使用 PFRelation 保存单元格的选择。到目前为止一切顺利,但是当我去检查数据浏览器解析时,我总是只能识别一个选定的单元格,我在哪里做错了?我实现 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];


}

最佳答案

您只查看第一行:

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

循环内的代码来自您的问题,我没有对其进行审查或编辑。

关于ios - UiCollectionView 在保存对象时没有选择正确的单元格 Parse.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19697265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com