【发布时间】:2014-11-19 07:51:00
【问题描述】:
我使用 Objective-C 开发了一个 Collection View 应用程序。我现在正在尝试使用 Swift 重新创建它,但我似乎无法翻译这最后两个 sn-ps 代码。
有人可以帮我翻译 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"];
}
}
【问题讨论】:
标签: iphone swift uicollectionview nsdictionary uicollectionviewcell