之前刚在storyboard中创建出cell的时候点击都有反应,但是之后填充数据之后整个cell就像被盖住了一样...没有反应了..
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as ReadingCard
let point = currentPoints![indexPath.item] as Point
cell.setTitle(point.title)
cell.setContent(point.content)
var imageData = self.imageCache.objectForKey(NSString(format: "%d", indexPath.item)) as? NSData
if let imageData_ = imageData{
cell.setImage(UIImage(data: imageData_))
}
return cell
}
然后cell的子类代码:
class ReadingCard: UICollectionViewCell {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var content: UITextView!
@IBAction func collectButtonClicked() {
println("collectButtonClicked")
}
@IBAction func commentButtonClicked(sender: AnyObject) {
println("commentButtonClicked")
}
@IBAction func naviButtonClicked(sender: AnyObject) {
println("naviButtonClicked")
}
func setTitle(title:NSString?){
if let title_ = title{
self.title.text = title_
}
}
func setContent(content:NSString?){
if let content_ = content{
self.content.text = content_
}
}
func setImage(image:UIImage?){
self.imageView.backgroundColor = UIColor.grayColor()
if let image_ = image{
self.imageView.image = image_
}
else{
}
imageView.contentMode = UIViewContentMode.ScaleAspectFit
}
}
是哪里出了问题呢...
发现不能把那些组件单独用一个view来当作容器,这样会导致无法交互。把多余的view去除就好了。