iOS:集合视图,selectItemAtIndexPath以编程方式不起作用

 6易0k醉人也s易 发布于 2023-02-11 09:07

我不知道为什么这不起作用.indexOfIcon是正确的,部分是正确的(用NSLog检查)如果我选择一个一切都是正确的.但这条线没有做什么......为什么?如果选中它应该有一个蓝色边框.这在"手动"但不是代码的情况下工作得很好.

- (void)viewWillAppear:(BOOL)animated
{
    NSUInteger indexOfIcon;
    if(self.mainCategory.icon){
        indexOfIcon = [self.icons indexOfObject: self.mainCategory.icon];
    } else {
        indexOfIcon = 0;
    }
    [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom];
}

zeiteisen.. 9

    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    cell.selected = YES;

并将选择单元格.

该命令[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom];告诉collectionView,单元格处于选中状态,但不设置单元格的状态.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有