【发布时间】:2015-05-02 18:44:19
【问题描述】:
我使用代码创建了一个 UITableView 和一个 UITableViewCell 的子类,它显示得非常好,直到我选择了单元格。
单元格的文本标签有时会向右移动或不移动
选择前问题的图像表示
选择后问题的图像表示
相关代码
class MyCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
// here I fixed the image at a specific point
self.imageView?.bounds = CGRectMake(0, 0, 100, 125)
self.imageView!.frame = CGRectMake(0, 0, 100, 125)
self.imageView?.contentMode = .ScaleAspectFill
} }
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = MyCell(style: UITableViewCellStyle.Default, reuseIdentifier: "FeedCell")
self.configureCell(cell, atIndexPath: indexPath)
return cell
}
func configureCell(cell: MyCell, atIndexPath indexPath: NSIndexPath) {
let item = self.items[indexPath.row] as MWFeedItem
cell.textLabel?.text = item.title
cell.textLabel?.font = UIFont.systemFontOfSize(12.0)
cell.textLabel?.numberOfLines = 0
}
【问题讨论】:
标签: ios uitableview swift tableview