图像未在 KDCircularProgress 中以编程方式设置
Images not being set programmatically in KDCircularProgress
我正在尝试在 KDCircularProgress 中设置图像,该图像位于 UITableViewCell 中。
当我从 StoryBoard 添加图像时它成功显示,但是当我尝试以编程方式添加它时图像没有出现。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellToReturn: DashBoardCell! = tableView .dequeueReusableCellWithIdentifier("DashBoardCell") as? DashBoardCell
if (cellToReturn == nil) {
cellToReturn = DashBoardCell(style: UITableViewCellStyle.Default, reuseIdentifier:"DashBoardCell")
}
let image: UIImage = UIImage(named: "ImageName")!
dImage = UIImageView(image: image)
dImage!.frame = CGRectMake(0,0,30,25)
dImage?.contentMode = UIViewContentMode.ScaleToFill
cellToReturn.dynamicImageView = dImage
dynamicImageView 是 UITableViewCell class 中的 UIImageView 插座,我正在尝试在视图控制器 class 的 table 视图单元格中设置动态图像,其中 TableView 委托方法是实施的。
我做错了什么?
我不确定 DashBoardCell
是什么样子,所以这可能是错误的,但似乎 dImage
从未添加到视图层次结构中。如果 DashBoardCell
已经在你的故事板中创建了 dynamicImageView
,而我不明白为什么它不会,那么你不必担心创建 UIImageView
,你可以只需将图像设置为
cellToReturn.dynamicImageView.image = UIImage(named: "ImageName")
如果没有,那么您需要添加类似
的内容
cellToReturn.contentView.addSubview(dImage)
或者如果 DashBoardCell
的 dynamicImageView
有一个 didSet
观察者,您可以在那里插入新视图。您还需要确保覆盖 DashBoardCell
中的 prepareForReuse
以删除 dynamicImageView
,因为您将在 cellForRowAtIndexPath
.
中创建一个新的
我正在尝试在 KDCircularProgress 中设置图像,该图像位于 UITableViewCell 中。
当我从 StoryBoard 添加图像时它成功显示,但是当我尝试以编程方式添加它时图像没有出现。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellToReturn: DashBoardCell! = tableView .dequeueReusableCellWithIdentifier("DashBoardCell") as? DashBoardCell
if (cellToReturn == nil) {
cellToReturn = DashBoardCell(style: UITableViewCellStyle.Default, reuseIdentifier:"DashBoardCell")
}
let image: UIImage = UIImage(named: "ImageName")!
dImage = UIImageView(image: image)
dImage!.frame = CGRectMake(0,0,30,25)
dImage?.contentMode = UIViewContentMode.ScaleToFill
cellToReturn.dynamicImageView = dImage
dynamicImageView 是 UITableViewCell class 中的 UIImageView 插座,我正在尝试在视图控制器 class 的 table 视图单元格中设置动态图像,其中 TableView 委托方法是实施的。
我做错了什么?
我不确定 DashBoardCell
是什么样子,所以这可能是错误的,但似乎 dImage
从未添加到视图层次结构中。如果 DashBoardCell
已经在你的故事板中创建了 dynamicImageView
,而我不明白为什么它不会,那么你不必担心创建 UIImageView
,你可以只需将图像设置为
cellToReturn.dynamicImageView.image = UIImage(named: "ImageName")
如果没有,那么您需要添加类似
的内容cellToReturn.contentView.addSubview(dImage)
或者如果 DashBoardCell
的 dynamicImageView
有一个 didSet
观察者,您可以在那里插入新视图。您还需要确保覆盖 DashBoardCell
中的 prepareForReuse
以删除 dynamicImageView
,因为您将在 cellForRowAtIndexPath
.