When I add a tableView in a viewController by default the tableView scrolls, but I want it static. Is it possible?
Here is my code:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return names.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableview.dequeueReusableCellWithIdentifier("cell") as! TableViewCell
cell.username.text = names[indexPath.row]
return cell
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 50.0
}
When the user scrolls back to a row, the table view will request its data again. The tableView(_:numberOfRowsInSection:) method tells the table view how many elements a section contains. The table view uses this information to prepare its scrolling area and display a scroll bar of the appropriate size.
For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views. The code of the table view data source often ends inside view controllers when it should go into a separate class.
Table views are more versatile than you might think. For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views.
In a scroll view, you need to figure the frame of each subview by yourself. You can use Auto Layout, but that still means you will need a lot of code to set all the constraints. In a scroll view, that’s not as easy to get right as it is in a regular UIView.
Swift 3, 4 and 5:
tableView.isScrollEnabled = false
Disable Scrolling in Interface Builder. Select the table view and the Attributes Inspector ⌥⌘4
Then uncheck Scrolling Enabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With