Scrollview with embedded tableview Scrollview with embedded tableview ios ios

Scrollview with embedded tableview


Ok it might be bit late now but still i m posting this as a tutorial !This is a less prefered way to achieve this. Better way would be,

Using table view controller as parent view and then using prototype cells as static cell(In 'n' numbers as per your requirement) as a card view or for any other use

The every different cell used would be considered as a section and no of prototype cells will be equal to no of sections in code as in snippet below

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {    return 3}override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {    if section == 2 {        return list.count    }    return 1}

number of rows in case of section 0 and 1 would be 1 as static partWhereas No of rows in case of section 2 i.e dynamic part would be equal to count of list.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {    var cell : CustomTableViewCell.swift = CustomTableViewCell.swift()    switch indexPath.section {        case 0:            cell = tableView.dequeueReusableCellWithIdentifier("staticCell1", forIndexPath: indexPath) as! CustomTableViewCell            break                case 1:            cell = tableView.dequeueReusableCellWithIdentifier("staticCell2", forIndexPath: indexPath) as! CustomTableViewCell            break                case 2:            cell  = tableView.dequeueReusableCellWithIdentifier("dynamicCell", forIndexPath: indexPath) as! CustomTableViewCell            break                default:            break    }    return cell;

}

and thats it! Work is done! Party!

I got reference from hereMixing static and dynamic sections in a grouped table view?


I mocked this up. My View hierarchy looks like this

ViewController's UIView...UIView (to act as a container view for all the scrollable content).......UIView (for the top content) - green.......UIView (for the bottom content) - blue............UILabel............UITableView (with scrollable content - more rows than visible)

I wired @IBOutlets to the UIScrollView (scrollView) and UIView (containerView) for the scrollable area.

in viewDidLoad I added:

scrollView.contentSize = containerView.frame.size

If I click anywhere outside the tableView (top area, text area, etc...) I scrolls the scrollView. If I try to scroll in the table view, the tableView scrolls (the scrollView does not).

Is that what you were trying to achieve?