Open mohsinalimat opened 4 years ago
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.
hello,
Not working :- When I build my projects with Xcode 11.4 shimmer not appear.![Simulator Screen Shot - Build on Xcode 11 4 version shimmer not appear iPhone 11 Pro Max - 2020-04-08 at 18 40 41](https://user-images.githubusercontent.com/973676/78788044-df009980-79c8-11ea-9ceb-6d28962baee5.png)
Working:- When I build my projects with Xcode 11.3 shimmer appear.![Simulator Screen Shot - Build on Xcode 11 3 version shimmer appear iPhone 11 Pro Max - 2020-04-08 at 18 40 55](https://user-images.githubusercontent.com/973676/78787899-a791ed00-79c8-11ea-94ae-daa9be1a860a.png)
Thanks, Mohsinali Matiya