如何将图像设置到 NSCollectionView 中?

How to set an image into an NSCollectionView?

下面是我的代码:

var  arrCategory:[NSString] =
         ["Australia","Austria","Belgium","Brazil","Cameroon","Canada","Chile","China","Denmark","Argentina"]

上面数组中给出的字符串是图片的名称。

将您的代码替换为:

cell.imageView?.image = UIImage(named: "\(self.arrCategory[indexPath.row]).png")
cell.LblName.text = "\(self.arrCategory[indexPath.row])"

我找到的答案问题在这里:

cell.imgView.image = NSImage(named:self.arrCategory[indexPath.item])
cell.lbl.stringValue =  arrlbl[indexPath.item] as String