2015-05-02 243 views
2

我已經使用代碼創建了UITableView和UITableViewCell的子類,並且它顯示完美無缺,直到我選擇單元格。UITableViewCell textLabel選擇的位置變化

該電池的爲textLabel將向右移動或不選擇 Image representation of the problem after selection

相關之後選擇之前轉移的問題有時

圖像表示

Image representation of the problem

圖像表示中的問題的代碼

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 
} 

回答

1

您應該在您的子類中真正定義您自己的圖像視圖和文本標籤(使用不同的名稱),並應用約束條件將它們與單元格大小相關聯,然後在控制器中設置行高度,被適當地顯示。

即使在第一張圖像中,圖像的大小也不正確,因此您在單元格和控制器之間的配置不匹配。而且,您當前使用的屬性在尺寸和位置方面應被視爲私人私有,因爲您不擁有設置視圖的這些功能的實現。

+0

對於任何人回到這個問題。每當單元格移動到選定狀態時,我的自定義單元格中的textLabel都會跳躍。我所做的只是在自定義單元格中定義自己的textLabel屬性,並從內置的textLabel屬性切換到新的自定義單元格。繁榮!問題解決了! – iOS4Life

相關問題