我有一个 UIImageViews 数组,我想将其显示到屏幕上。然而,我似乎无法做到这一点。我像这样声明了我的 UIImageViews
数组:
class EventCell: UITableViewCell, CellDelegate{
@IBOutlet var eventName: UILabel!
@IBOutlet var eventLocation: UILabel!
@IBOutlet var attendeesImages: [UIImageView]!
}
我有一个显示 EventCell
内容的函数,如下所示:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Dequeue a "reusable" cell
let cell = tableView.dequeueReusableCellWithIdentifier(eventCellIdentifier) as! EventCell
setCellContents(cell, indexPath: indexPath)
return cell
}
//Set contents of Event Cell.. self.events is a global array
//which have information that EventCell objects need to display
func setCellContents(cell:EventCell, indexPath: NSIndexPath!){
let item = self.events[indexPath.section]
var count = 0
cell.eventName.text = item.eventName()
cell.eventLocation.text = item.eventLocation()
cell.attendeesImage.removeAll(keepCapacity: false)//Remove old images before adding new
for value in item.attendeesImage {
let newImageView = UIImageView(image : value)
newImageView.clipsToBounds = true
newImageView.layer.cornerRadius = newImageView.frame.size.width / 2
cell.attendeesImage.append(newImageView)
println("Count inside: \(cell.attendeesImage.count)")
}
}
我打印了 cell.attendeesImage
的count
,以确保没有添加无关的图像,并且它似乎被证明是正确的。但是,我不知道为什么我的图像没有显示。我确保将 cell.attendeesImage
挂接到我的 EventCell
的 Storyboard中的 IBCollection(因为它是一个数组)。关于为什么这没有出现的任何想法?谢谢!
最佳答案
您使用了错误的集合 channel “attendeesImages”。
加载 View 时,将创建数组 attendeesImages 并使用您在界面生成器中创建的 ImageView 进行初始化。但是,如果删除所有引用,您就失去了 channel 和真实 View 之间的链接。您正在创建的新 ImageView 不是单元格中的 ImageView 。它们仍然是单元格的 subview ,但现在您没有对它们的 iboutlet 引用。
解决方案:不要从数组中删除值。只需修改每个 ImageView 中的图像即可。
关于ios - UIImageView 数组不显示内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376029/