# Uitextview in uitableview

**URL:** <https://forums.kodeco.com/t/uitextview-in-uitableview/14779>\
**Category:** Swift\
**Created:** [May 12, 2016, 11:49am UTC](https://forums.kodeco.com/t/uitextview-in-uitableview/14779 "2016-05-12T11:49:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumya](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/soumya/32/32433_2.png) [@soumya](https://forums.kodeco.com/u/soumya)\
**Post date:** [May 12, 2016, 11:49am UTC](https://forums.kodeco.com/t/uitextview-in-uitableview/14779/1 "2016-05-12T11:49:32Z")

</div>

I have attached a UItextView in tableview cell. Now I want to insert an UIimage behind it like a chat bubble.But everytime I scroll the tableview , the Uitextview becomes smaller in width and longer in height. The text also gets resized from single to multi line. Also ,the same thing happens when I scroll back to an earlier cell ( for example the first row). I can’t figure out why this is happening.

My code is: (SampleTableViewCell is my custom UItableViewCell class and lblTitle is my UitextView outlet.)

```
    func tableView(tableView: UITableView, willDisplayCell cell: SampleTableViewCell, forRowAtIndexPath indexPath: NSIndexPath) 
 {

    cell.lblTitle.removeConstraints(cell.lblTitle.constraints)

    let stringTitle = carName[indexPath.row] as String //carName is an array
    cell.lblTitle.text=stringTitle
    cell.lblTitle.sizeToFit()

    let h = cell.lblTitle.frame.size.height
    let w = cell.lblTitle.frame.size.width
    let constraints = NSLayoutConstraint(item: cell.lblTitle, attribute: .Width, relatedBy: .Equal, toItem: cell.lblTitle, attribute: .Height, multiplier: 0, constant: w)
    cell.lblTitle.addConstraint(constraints)

    let kl = UIImage(imageLiteral: "bubble")
    let imageView = UIImageView(frame:CGRectMake(0, 0, w, h))
    imageView.image = kl
    imageView.alpha = 0.4
    cell.lblTitle.addSubview(imageView)
    cell.lblTitle.sendSubviewToBack(imageView)
  }

```

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [May 14, 2016, 5:45pm UTC](https://forums.kodeco.com/t/uitextview-in-uitableview/14779/2 "2016-05-14T17:45:04Z")

</div>

That is because the cells get redrawn as they are scrolled on and off the screen.

Did you create a custom uitableviewcell subclass?

You need to move the layout changes to your uitableviewcell subclass methods.
