如果用户选择超过4张图像,则显示警报框。
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *secell = [collectionView cellForItemAtIndexPath:indexPath];
if (indexPath.row == 4) {
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"OK Dailog"
message:@"This is OK dialog"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles: nil];
[alert show];
}
else
{
UIImageView *imgselect = (UIImageView *)[secell viewWithTag:110];
imgselect.image = [UIImage imageNamed:@"selectimg.png"];
}
}
3条答案
按热度按时间pcrecxhr1#
您应该检查所选项目的数量,而不是检查
indexPath.row
。可以尝试类似的操作vx6bjr1n2#
这应该在委托方法
collectionView:shouldSelectItemAtIndexPath
中设置cgyqldqp3#
适用于swift 5