【发布时间】:2016-01-24 21:35:37
【问题描述】:
我想在集合视图单元格中插入三张图片,三张图片。每个单元格一张图片。只有一个部分。 但是当模拟器显示黑屏时,没有任何图像。 这是我的代码的一部分:
import Foundation
import UIKit
class CatImagesViewController:UIViewController,UICollectionViewDataSource,UICollectionViewDelegate
{
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let con = CatService(test:"test")
let temp = NSUserDefaults()
let number = temp.integerForKey("num_of_images")
var title_array:Array<String> = con.imageNamesForCategoryAtIndex(number)
var string:String = title_array[indexPath.row]
print("indexPath.row \(indexPath.row)");
print("string is \(string)")
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("firstCollectionCell", forIndexPath: indexPath)
let imageview:UIImageView=UIImageView(frame: CGRectMake(50, 50, self.view.frame.width-200, 50))
let image:UIImage = UIImage(named:string)!
imageview.image = image
// self.view.addSubview(imageview)
cell.contentView.addSubview(imageview)
return cell
}
}
我修改了cell.contentView.addSubview(image view),但还是黑屏。
【问题讨论】:
-
单元格的高度是多少?
-
不知道如何设置单元格的高度......
标签: ios swift ios-autolayout