2016-11-09 14 views
0

私はカスタムスタイルUITableviewCellを持っています。それは他のもののデフォルトの高さを持っています。私は字幕のスタイルでtableviewセルを使用しています。そしてそれはうまくやっているが、テーブルビューのセルの高さを計算するのに問題があり、私はUITableviewAutomaticDimensionを使っていますが、それは動作しません。
ここに私のコードあなたのviewDidLoadでUITableViewCellスタイルの字幕マルチラインが動作しない

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if(indexPath.row==0){ 
     var cell: ImageCell! = tableView.dequeueReusableCellWithIdentifier("ImageCell") as? ImageCell 
     if cell == nil { 
      tableView.registerNib(UINib(nibName: "ImageCell" ,bundle: nil), forCellReuseIdentifier: "ImageCell") 
      cell = tableView.dequeueReusableCellWithIdentifier("ImageCell") as? ImageCell 
     } 
     return cell 
    }else{ 

     var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("SubtitleCell") 
     if (cell == nil) { 
      cell = UITableViewCell.init(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "SubtitleCell") 
      cell!.backgroundColor = UIColor.brownColor() 
      cell!.textLabel?.font = UIFont.init(name: "HelveticaNeue", size: 15) 
      cell!.textLabel?.textColor = UIColor.blackColor() 
      cell!.textLabel?.highlightedTextColor = UIColor.lightGrayColor() 
      cell!.selectedBackgroundView = UIView.init() 
     } 
     cell!.textLabel?.text = "TExt" 
     cell!.detailTextLabel!.text="Keep in mind that UITableView is defined as an optional in the function, which means your initial cell declaration needs to check for the optional in the property. Also, the returned queued cell is also optional, so ensure you make an optional cast to UITableViewCell. Afterwards, we can force unwrap because we know we have a cell." 
     allowMultipleLines(cell!) 
     cell!.imageView?.image = UIImage(named: "IconProfile") 

     return cell! 
    } 
} 
func allowMultipleLines(tableViewCell:UITableViewCell) { 
    tableViewCell.detailTextLabel?.numberOfLines = 0 
    tableViewCell.detailTextLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping 
} 
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if(indexPath.row==0){ 
     return 172 
    }else{ 
     return UITableViewAutomaticDimension 
    } 
} 

result

+0

可能な重複http://stackoverflow.com/questions/36587126/autolayout-ignores-multi-line-detailtextlabel-when-calculating-uitableviewcell-h –

答えて

0

()あなたは

yourTableViewName.rowHeight = UITableViewAutomaticDimension 

を書き、もう一つの方法に

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if(indexPath.row==0){ 
     return 172 
    }else{ 
     return UITableViewAutomaticDimension; 
    } 
} 
を追加する必要があるメソッドがあります

は、私はこれがあなた

+0

ませブロそれが機能していないのに役立ちます願っています結果は同じです。 –

+0

自動レイアウトを使用していますか? –

+0

はいautolayoutがチェックされています。 –

関連する問題