0

I am having trouble understanding how to embed my view into a scroll view with a dynamic height. I have managed to create scroll views before, but only with a static height. How would an iPhone application, such as Facebook or Instagram, for example, manage to create a scroll view for an entire feed of dynamic-height data. To this point I have used storyboards to create the scroll views, but I am assuming that this done in code would be much better.

class connectDetailsViewController: UIViewController {
    override func viewDidLoad() {
    super.viewDidLoad()
    //set up variables with data
    fillData()
}
override func viewWillAppear(animated: Bool) {
    let nameTitleString = String(businesses[businessNum]["name"]!)
    nameTitle.text = nameTitleString

    processTimes() // Adds information for the hours of operation, if applicable

    processDetails() //Adds information for the details if possible (a few sentences to a few paragraphs)
}

}

processDetails() and ProcessTimes() will edit the content in a stack view, how can I create a scroll view to encompass both of these stack views at the correct height?

Alec O
  • 1,697
  • 1
  • 18
  • 31

1 Answers1

0

Generally, for providing a feed of content such as a Facebook timeline you would likely use a UITableView as it manages the reuse of cells and the overall contentSize internally using it's delegate methods on the dataset to determine number of rows, estimated row heights and so on. The tableView actually uses a scrollView to acheive this but it handles it internally.

In my opinion this would be your best approach, to do this without using a tableView you would need to replicate alot of the logic that it performs on your behalf.

The main thing to remember with a scrollView is that it can load content that is larger than the scrollView, and then manages scrolling/panning/zooming to allow you to view the larger content.

If you just wanted to know how to do this yourself, you would likely need a parent container in the scrollview and then you would keep adding new views into it, adjusting the scrollViews contentSize height each time you add new content

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • I agree with @Scriptable. It is highly recommended to use `UITableView` for such a thing, but if you plan on displaying items other than cells then you would need a scroll view that dynamically changes height. I answered a very similar question with a specific process for going about this here: http://stackoverflow.com/a/37367119/6361557 – Adam H. May 29 '16 at 15:50