因此,我创建了一个自定义表格视图单元格,左侧有一个标签,右侧有一个UIImageView。 标签有100和UIImageView的一个标签110在xcode 6中使用swift自定义表格视图单元
我的代码标签如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("ThemeCell") as UITableViewCell
let theme = themes[indexPath.row]
var themeName = cell.viewWithTag(100) as? UILabel
themeName?.text = theme.themeName
let themeImage = cell.viewWithTag(110) as? UIImageView
themeImage?.image = UIImage(named: "test.png")
//1
//cell.imageView?.image = UIImage(named: "test.png")
println("The loaded image: \(themeImage?.image)")
return cell;
}
按原样,则显示THEMENAME但themeImage没有出现,尽管从println似乎是加载图像。如果我取消注释1中的代码,图像将显示在自定义单元格中,但当然不会显示在正确的位置,因为它未添加到我在IB中创建的UIImageView。 任何想法我可能做错了什么?标签都是正确的。 谢谢
我在IB中有一个自定义单元,以便能够添加UIImageView,但我没有创建一个扩展UITableViewCell的MyCustomCell类。我不认为我需要。我只需要有一个UILabel和UIImageView。 – 2014-09-23 16:21:56
添加以下代码以查看是否可以显示'UIImageView':themeImage?.backgroundColor = UIColor.greenColor()'。 – 2014-09-23 16:35:22
http://stackoverflow.com/questions/24170922/creating-custom-tableview-cells-in-swift/38470749#38470749 – 2016-07-20 01:25:08