I want SkeletonView to disappear after data acquisition
SkeletonView does not disappear after data acquisition
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 (1.4)
Latest Xcode version
Swift 4.0
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
}
}
Most helpful comment
Hi @son,
To hide the skeleton you need to use this method
hideSkeletonSo you method
getContarctsshould look like this:by default
hideSkeletonmethod reloads the tableview automaticallyLet me know if your problem is solved with this solution, in order to close this issue :)
Thanks