SkeletonView
SkeletonView copied to clipboard
Not working shimmer
hello,
-
Not working :- When I build my projects with Xcode 11.4 shimmer not appear.

-
Working:- When I build my projects with Xcode 11.3 shimmer appear.

Thanks, Mohsinali Matiya
self.view.isSkeletonable = true
When I used above line with below line then work fine.
self.view.showAnimatedGradientSkeleton()
`struct Photo: Codable { let albumID, id: Int let title, url, thumbnailURL : String
enum CodingKeys: String, CodingKey {
case albumID = "albumId"
case thumbnailURL = "thumbnailUrl"
case id, title, url
}
}
class PhotosController: UITableViewController {
private var dataSource: [Photo] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(PhotoCell.self, forCellReuseIdentifier: "cell")
tableView.separatorStyle = .none
tableView.estimatedRowHeight = 120.0
view.isSkeletonable = true
tableView.isSkeletonable = true
guard let url = URL(string: "https://jsonplaceholder.typicode.com/photos") else {
return
}
let request = URLRequest(url: url)
view.showAnimatedSkeleton()
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
if let decodedResponse = try? JSONDecoder().decode([Photo].self, from: data) {
DispatchQueue.main.async {
self.dataSource = decodedResponse
self.view.hideSkeleton()
self.tableView.reloadData()
}
}
}
}.resume()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
}
extension PhotosController : SkeletonTableViewDataSource {
func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
return "cell"
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PhotoCell
cell.textLabel?.text = dataSource[indexPath.row].title
cell.detailTextLabel?.text = dataSource[indexPath.row].url
return cell
}
}
class PhotoCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
isSkeletonable = true
textLabel?.isSkeletonable = true
textLabel?.numberOfLines = 3
detailTextLabel?.isSkeletonable = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
} ` I am trying to achieve this from programmatically but it is not working. please help me.