ios - 我显示了单元格,但我希望当我按下按钮时图像显示在 Collection View 单元格中

标签 ios swift uicollectionviewcell

我想在按下按钮时插入数组中的图像

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {


       let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath)
        cell.backgroundColor = UIColor.orangeColor()

        return cell
    }




    func buttonCreateStickerPressed(sender: UIButton!){
        let stickerName = "Sticker Number "+String(stickerDictionary.count+1)
        let stickerNumber = stickerDictionary.count+1
        makeSticker(stickerName, stickerNumber: stickerNumber)
        // let count = stickerArray.count



    }

最佳答案

您可以尝试 reloadData,然后设置图像,或者如果只对某些索引执行此操作,您可以尝试 reloadDataForRowIndexes:columnIndexes,然后在选定的行中设置图像

关于ios - 我显示了单元格,但我希望当我按下按钮时图像显示在 Collection View 单元格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35916951/

相关文章:

ios - UICollectionview 单元格在滚动时发生变化

ios - UITableView 在向其添加新单元格时跳转到顶部。如何预防呢?

ios - 选择 UIButton 时未正确响应

ios - 实现 ErrorProtocol 时,不断出现错误 1) 使用未声明的类型 ErrorProtocol 2) 类型不符合协议(protocol) RawRepresentable

swift - 列出专辑标题时如何使用右侧的表格 View "index"?

ios - Collection View 单元格的多项选择

ios - 如何通过生成 pdf 的缩略图来预加载 CollectionView 中的图像?

ios - Xcode 编辑器在编译时花费太多时间

iphone - 如何在 Objective-C 中获取外部 ip

iOS——访问 block 内的本地变量