Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将collectionView转换为Swift以配置自定义单元格_Iphone_Swift_Uicollectionview_Nsdictionary_Uicollectionviewcell - Fatal编程技术网

Iphone 将collectionView转换为Swift以配置自定义单元格

Iphone 将collectionView转换为Swift以配置自定义单元格,iphone,swift,uicollectionview,nsdictionary,uicollectionviewcell,Iphone,Swift,Uicollectionview,Nsdictionary,Uicollectionviewcell,我已经用Objective-C开发了一个Collection View应用程序。我现在正试图用Swift重新创建它,但我似乎无法翻译最后两段代码 有人能帮我翻译setupCell函数以配置自定义单元格吗? override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let

我已经用Objective-C开发了一个Collection View应用程序。我现在正试图用Swift重新创建它,但我似乎无法翻译最后两段代码

有人能帮我翻译setupCell函数以配置自定义单元格吗?

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

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell

    ###Translate to Swift
    cell setupCell:[self.titles.objectAtIndex(indexPath.row)

    return cell
}

class CollectionViewCell: UICollectionViewCell {

  ###Translate to Swift
  -(void)setupCell:(NSDictionary *)dictionary {
    NSString *imageFileName = [dictionary valueForKey:@"image"];
    self.imageView.image = [UIImage imageNamed:imageFileName];

    self.nameLabel.text = [dictionary valueForKey:@"name"];

  }
}
查看此代码:

 func setUpCell(dictonary:NSDictionary){

    var imageFileName : NSString = dictonary.valueForKey("image") as NSString
    self.imageView.image = UIImage(named:imageFileName)
    self.nameLabel.text = dictonary.valueForKey("name") as NSString

}
让我知道它是否适用于您,因为我没有测试它

函数是否有效:)。您知道如何将此单元格setupCell:[self.titles.objectAtIndex(indexath.row)转换为self.setupCell(self.title.objectAtIndex(indexath.row))