SkeletonView does not disappear after data acquisition

Created on 28 Nov 2018  路  4Comments  路  Source: Juanpe/SkeletonView

What did you expect to happen?

I want SkeletonView to disappear after data acquisition

What happened instead?

SkeletonView does not disappear after data acquisition

Steps to reproduce the behavior

import UIKit
import SkeletonView

final class CompanyClientListViewController: UIViewController {

    @IBOutlet private weak var tableView: UITableView!

    private var joinedContracts = [(Contract, Pillar)]()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
        getContarcts()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        tableView.showAnimatedSkeleton()
    }

    private func setupView() {
        tableView.register(UINib(nibName: "ContractCell", bundle: nil), forCellReuseIdentifier: ContractCell.description())
        tableView.delegate = self
        tableView.dataSource = self
        tableView.isSkeletonable = true
    }

    private func getContarcts() {
        API.Contract.getContractsWithPillar { (joinedContracts) in
            self.joinedContracts = joinedContracts
            DispatchQueue.main.async {
                self.tableView.reloadData()
                self.tableView.isSkeletonable = false
            }
        }
    }
}

extension CompanyClientListViewController: UITableViewDelegate {

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let viewController = CompanyContractViewController.instantiate(withStoryboard: "CompanyContract")
        viewController.pillar = joinedContracts[indexPath.row].1
        viewController.contractID = joinedContracts[indexPath.row].0.contractID
        navigationController?.pushViewController(viewController, animated: true)
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 70
    }
}

extension CompanyClientListViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        joinedContracts.isEmpty ? tableView.setEmptyView(viewType: .pillarContract) : tableView.restore()
        return joinedContracts.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: ContractCell.description(), for: indexPath) as! ContractCell
        cell.pillar = joinedContracts[indexPath.row].1
        cell.contract = joinedContracts[indexPath.row].0
        return cell
    }
}

extension CompanyClientListViewController: SkeletonTableViewDataSource {

    func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
        return ContractCell.description()
    }
}

SkeletonView Environment

SkeletonView (1.4)
Latest Xcode version
Swift 4.0

鉂攓uestion

Most helpful comment

Hi @son,
To hide the skeleton you need to use this method hideSkeleton
So you method getContarcts should look like this:

private func getContarcts() {
        API.Contract.getContractsWithPillar { (joinedContracts) in
            self.joinedContracts = joinedContracts
            DispatchQueue.main.async {
                self.tableView.hideSkeleton()
            }
        }
    }

by default hideSkeleton method reloads the tableview automatically

Let me know if your problem is solved with this solution, in order to close this issue :)

Thanks

All 4 comments

Hi @son,
To hide the skeleton you need to use this method hideSkeleton
So you method getContarcts should look like this:

private func getContarcts() {
        API.Contract.getContractsWithPillar { (joinedContracts) in
            self.joinedContracts = joinedContracts
            DispatchQueue.main.async {
                self.tableView.hideSkeleton()
            }
        }
    }

by default hideSkeleton method reloads the tableview automatically

Let me know if your problem is solved with this solution, in order to close this issue :)

Thanks

Thank you very much for your kind response soon!
The problem was solved!

If I tap Cell while SkeletonView is displayed under the same code, there is an error (Fatal error: Index out of range) with didSelectRowAt (), how can I prohibit userInteraction only during SkeletonView display?
@Juanpe

If I tap Cell while SkeletonView is displayed under the same code, there is an error (Fatal error: Index out of range) with didSelectRowAt (), how can I prohibit userInteraction only during SkeletonView display?
@Juanpe

You can call this method to prevent index out of range error:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if !yourTableView.isSkeletonActive {
//Your code goes here
}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GauravTechbirds picture GauravTechbirds  路  4Comments

adelbios picture adelbios  路  6Comments

ghost picture ghost  路  7Comments

robinkunde picture robinkunde  路  8Comments

raphaklr picture raphaklr  路  5Comments