我已将图像添加到uitableview的单元格中,但当我尝试更改图像的位置时,没有发生任何事情。
这是我的tableview函数的样子:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
let article = articles[indexPath.row] as Article
cell.textLabel!.text = article.title
cell.imageView?.image = article.image
let rect = CGRect(x: 0, y: 0, width: 100, height: 100)
cell.imageView?.frame = rect
return cell
}
正如您所见,图像显示但位置保持不变:
为什么会发生这种情况?
答案 0 :(得分:1)
UITableViewCell
覆盖layoutSubviews
class MyCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
self.imageView?.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
}
}