【发布时间】:2015-11-15 23:19:02
【问题描述】:
我正在尝试将图像放入我的UITableView。该表设置有自定义子类单元格。在子类中我有网点:
@IBOutlet var titleLabel: UILabel!
`@IBOutlet var pillarIcon: UIImageView!`
在超类中,我为两者创建了一个NSMutableArray:
var objects: NSMutableArray! = NSMutableArray()
var imageObjects: NSMutableArray! = NSMutableArray()
我将东西放入viewDidLoad 方法中的数组中每个数组有 4 个项目。
所以当我调用项目时:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.objects.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell
cell.titleLabel.text = self.objects.objectAtIndex(indexPath.row) as? String
cell.pillarIcon.image = self.imageObjects.objectAtIndex(indexPath.row) as? UIImage
return cell
}
cell.titleLabel.text 项目出现,但 cell.pillarIcon.image 中的图像没有出现在表格中。
我已经为此工作了几个小时,感觉就像在兜圈子。图像文件也已加载到主文件中,所以这不是问题。
提前致谢。
【问题讨论】:
-
您是否尝试过更具体的数组类型?试试: var objects = [UIImage]() var imageObjects = [String]()
-
如何在
imageObjects属性中加载图像值? -
@whyceewhite 我正在像这样加载图像:
self.imageObjects.addObject("book.jpg")self.imageObjects.addObject("bookmark.png") -
检查
self.imageObjects.objectAtIndex(indexPath.row) as? UIImage是否返回 nil。如果不是,则问题出在您的自定义表格单元格上。 -
你可以试试 cell.pillarIcon.image = UIImage(named: "Demo.png").构象。
标签: ios swift uitableview cocoa-touch swift2