SkeletonView icon indicating copy to clipboard operation
SkeletonView copied to clipboard

SkeletonTableViewDataSource numberOfRowsInSection never called

Open Erumaru opened this issue 5 years ago • 9 comments

⚠️ Please fill out this template when filing an issue.

🙏🏼 Please check if it already exists other issue related with yours.

What did you do?

Created UITableView with isSkeletonable set to true. All cells and its subview also isSkeletonable set to true. Implemented SkeletonTableViewDataSource and numberOfRowsInSection in MyViewController class. Set UITableView's dataSource to MyViewController. Called showSkeleton().

What did you expect to happen?

I expected UITableView to use

func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int

What happened instead?

It always uses

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int

Steps to reproduce the behavior

Steps mentioned in what did you do

SkeletonView Environment

SkeletonView version: 1.8.6 Xcode version: 11.3.1 Swift version: 5.0

Erumaru avatar Feb 24 '20 12:02 Erumaru

showSkeleton should be called on your collection/tableView instead of your view :)

Me too.

aipinn avatar Mar 05 '20 06:03 aipinn

@paulanatoleclaudot-betclic thanks for your response, but I call it on collection view.

Erumaru avatar Mar 09 '20 10:03 Erumaru

Me too. It doesn't calculate how many cells need to populate the whole table view.

tadeha avatar Mar 16 '20 07:03 tadeha

Boys, I resolved it. I used vc addsubview tableView.

First, you must set vc self.view.isSkeletonable = true Second, for tableView must use estimatedRowHeight.

tableView.estimatedRowHeight = 130
tableView.rowHeight = UITableView.automaticDimension

aipinn avatar Mar 17 '20 13:03 aipinn

Same problem here with 1.8.6 and 1.8.7. Fixed by reverting to version 1.8.5. I am on Xcode 11.3.1 and Swift 5.1

mg-partec avatar Apr 29 '20 11:04 mg-partec

Got the same issue. But instead of composing my own custom TableViewController (UIViewController + UITableView), I instead opted to subclassing UITableViewController. So somehow, you need to explicitly set this controller as the dataSource of the tableView to make SV work.

class CustomTableViewController: UITableViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    ...
    tableView.dataSource = self
  }
  ...
}

extension CustomTableViewController: SkeletonTableViewDataSource {
  ...
}

Without this, when you set a breakpoint at line 35 of the file UITableView+CollectionSkeleton, guard always fails because it detects that your dataSource is of type _UIFilteredDataSource and not SkeletonTableViewDataSource.

Here's my spec: SkeletonView: 1.8.7 | Swift: 5 | Xcode: 11.2.1

mkval avatar Jun 19 '20 06:06 mkval

Boys, I resolved it. I used vc addsubview tableView.

First, you must set vc self.view.isSkeletonable = true Second, for tableView must use estimatedRowHeight.

tableView.estimatedRowHeight = 130
tableView.rowHeight = UITableView.automaticDimension

Yep. When you find all the cells are not displaying with showSkeleton(), please set the estimatedRowHeight. Otherwise, they won't show it!!! I think it's better to put this into README. @Juanpe Maybe a Q&A part.

XiaoxiaYao avatar Aug 25 '21 16:08 XiaoxiaYao

Hi @XiaoxiaYao, you're right. Actually, this info is already in the README file:

Screenshot 2021-08-25 at 18 57 24

But, yes, I agree with you that a Q&A or FAQ section could be very useful. Feel free to create it :)

Juanpe avatar Aug 25 '21 16:08 Juanpe