title: Setting content size of UIScrollView to its frame width when UIScrollView is located in a Custom UITableViewCell
body: <p>I have added a <code>UIScrollView</code> to a custom <code>UITableViewCell</code>.  </p>
  
  <p>I designed the cell and added the <code>scrollview</code> in my storyboard and set the constraints there.  The cell and the scrollview's frame are displaying correctly.  </p>
  
  <p>However, I do not want my <code>scrollview</code> to scroll horizontally, so I want to set the <code>contentSize.width</code> property to the width of the scroll view's frame.  I am setting my code for this inside my custom UITableViewCell class' <code>awakeFromNib</code> method.  </p>
  
  <p>The problem is that this method is apparently called before the frame's width is adjusted to fit the current size device, so I am getting the width to be the width in the storyboard, which is too long.  </p>
  
  <p>I have seen online that the methods <code>viewDidLoad</code> and <code>viewDidLayoutSubviews</code> are called after the sizes are adjusted, but these are methods inside the <code>UIViewController</code> class.  They do not appear to be a part of the <code>UITableViewCell</code> class.  </p>
  
  <p>I do not know how to get a reference to every custom cell inside the <code>UIViewController</code> in order to set the values in the suggested methods.  </p>
  
  <p>Can someone tell me how to do this, or where I can put this code inside the <code>UITableViewCell</code> class?  Thanks!</p>
  
  <p>Here is my UITableViewCell class for reference.</p>
  
  <pre><code>import UIKit
  
  class CustomTableViewCell: UITableViewCell, UIScrollViewDelegate {
  
  
      @IBOutlet weak var winLoseValueLabel: UILabel!
      @IBOutlet weak var dateLabel: UILabel!
      @IBOutlet weak var newTotalLabel: UILabel!
      @IBOutlet weak var locationLabel: UILabel!
      @IBOutlet weak var playersScrollView: CustomTableCellScrollView!
      @IBOutlet weak var scrollContentView: UIView!
  
      var numLinesInScrollView : CGFloat?
      var tblView : UITableView?
      var people : String?
  
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
          self.playersScrollView.tblView = tblView
          numLinesInScrollView = 0.0
          self.playersScrollView.contentSize.width = self.scrollContentView.frame.width
          self.playersScrollView.contentSize.height = 100
          self.playersScrollView.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 0, alpha: 0.25)
          self.playersScrollView.addSubview(self.scrollContentView)
      }
  
      override func layoutSubviews() {
          super.layoutSubviews()
          //self.playersScrollView.contentSize.width = self.playersScrollView.frame.size.width
          /*****Updating the contentSize did not work in this method either*****/
      }
  
      override func setSelected(selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
          // Configure the view for the selected state
      }
  }
  </code></pre>
  
  <p>Here is the View Controller.</p>
  
  <pre><code>import UIKit
  
  class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
      @IBOutlet weak var tblView: UITableView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.    
      }
  
      override func viewDidLayoutSubviews(){
          super.viewDidLayoutSubviews() 
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return dataMgr.data.count
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          let cell : CustomTableViewCell = self.tblView.dequeueReusableCellWithIdentifier("ledgerCell", forIndexPath : indexPath) as! CustomTableViewCell
  
          var values = dataMgr.data[indexPath.row]
          cell.newTotalLabel?.text = "\(values.newTotal)"
          cell.winLoseValueLabel?.text = "\(values.newTotal - values.currentTotal)"
          cell.dateLabel?.text = "5/17/2015"
          //cell.playersScrollView.contentSize.width = cell.playersScrollView.frame.width
          /*****Adjusting contentSize did not work here either*****/
          cell.tblView = self.tblView
  
          return cell
      }
  
  }
  </code></pre>