vinay
vinay

Reputation: 132

How to disable the scrolling of table view for first Section @iOS

I have two sections in my table view , I want to have scroll enabled for 2nd section and disabled for 1st section , how could I achieve it ?

Upvotes: 1

Views: 1366

Answers (4)

In your case I would use Section Header for the second section and make that header as customView.

You need to call the following functions:

1) viewForHeaderInSection 

    if section == 2 {
      ... customize your header view
    }

2) heightForHeaderInSection
  
    if section == 2 {
      ... set height
    }

Upvotes: 0

Rajesh Kumar
Rajesh Kumar

Reputation: 1

@vinay

Try this solution

  1. Take a view at the top of view controller.
  2. Below that view take tableview.
  3. Set table style to Grouped. It makes sections of tableview scrollable.

Upvotes: 0

ItsKazBorn
ItsKazBorn

Reputation: 19

A way to workaround it is having 2 UITableViews, one with scrolling disabled while the other has it enabled.

You can disable scrolling on a UITableView on the Attributes inspector while it's selected. There's a whole section on the Scroll View the UITableView has, and in the second subsection there's a toggle for "Scrolling Enabled" which is on by default.

[Edit: I've just seen the other comment, and I'd still recommend 2 UITableViews if you are dealing with dynamic content. If the content from the 1st section isn't dynamic, you may use an UIView as it'll save a lot of time just by not needing to implement 2 UITableViews in a single UIViewController]

Upvotes: 1

Joel Bell
Joel Bell

Reputation: 2718

A UITableView as a whole is a ScrollView so there is no way to only scroll one section. I'd suggest moving what is in the first section into a UIView, then placing a UITableView below that UIView that just has a single section that contains the views you had in the section of the view.

This way the top part will not scroll, but the bottom part will.

Upvotes: 1

Related Questions