gpt4 book ai didi

ios - 当我调用 CollectionView :didSelectItemAtIndexPath 时没有任何反应

转载 作者:行者123 更新时间:2023-11-28 20:04:12 24 4
gpt4 key购买 nike

我正在尝试调用突出显示我拥有的 UICollectionViewCells 的方法。一切正常,但是当 UIView 首次加载时,我正尝试像这样选择 Collection View 中的第一项

[photoCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];

这就是我的选择方法,在选择照片时效果很好。

#pragma mark -- UICollectionView Delegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
oldCell = currentCell;
currentCell = indexPath;

// animate the cell user tapped on
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
UICollectionViewCell *oCell = [collectionView cellForItemAtIndexPath:oldCell];

NSDictionary *currentSelectedDict = [imageArray objectAtIndex:indexPath.row];
UIImage *updatePreviewImage = [UIImage imageWithData:[currentSelectedDict objectForKey:@"DImage"]];
[previewImageView setImage:updatePreviewImage];
previewImageView.userInteractionEnabled = YES;

typeTextF.text = [currentSelectedDict objectForKey:@"DocumentType"];
descriptionText.text = [currentSelectedDict objectForKey:@"DocumentDescription"];
dateLabel.text = [NSString stringWithFormat:@"%@", [currentSelectedDict objectForKey:@"DateString"]];


[UIView animateWithDuration:0.2
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
NSLog(@"animation start");
[cell setBackgroundColor:[UIColor whiteColor]];
[oCell setBackgroundColor:[UIColor clearColor]];
}
completion:^(BOOL finished){
NSLog(@"animation end");
[cell setBackgroundColor:[UIColor whiteColor]];
[oCell setBackgroundColor:[UIColor clearColor]];
}
];


}

我读到也许您可以过早调用此方法?我不确定情况是否如此,但我不知道如何测试它,或者我使用的代码是否正确。

最佳答案

试试这个。覆盖 UICollectionViewCell 类并添加此方法

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];

[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{

self.contentView.backgroundColor = [UIColor redColor];
} completion:^(BOOL finished) {
self.contentView.backgroundColor = [UIColor greenColor];
}];
}

关于ios - 当我调用 CollectionView :didSelectItemAtIndexPath 时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22653869/

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