I know they are nil because I tried to debug them and saw the values were nil so that was why they are not displaying. How can I display them then?ImageController is constant that takes the function fetchItemArtwork which takes a url and turns it into a UIImage. CurrentPlayer is my class with the values for update. This is my ViewControllerclass ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { @IBOutlet weak var collections: UICollectionView! @IBOutlet weak var theSearch: UISearchBar! var cPlayerArr = [CurrentPlayer]() override func viewDidLoad() { super.viewDidLoad() let layout = UICollectionViewLayout() downloadJSON { self.collections.reloadData() //print("***\(self.cPlayerArr)***") } self.collections.register(CurrentPlayerCell.self, forCellWithReuseIdentifier: "playercell") self.collections.delegate = self self.collections.dataSource = self } func downloadJSON(completed: @escaping () -> ()) { let url = URL(string: "https://api.sportsdata.io/v3/nba/scores/json/Players?key=apiKey") URLSession.shared.dataTask(with: url!) { (data, response, error) in if error == nil { do { //put data in here self.cPlayerArr = try JSONDecoder().decode([CurrentPlayer].self, from: data!) DispatchQueue.main.async { completed() } } catch { print("JSON Error") } } } .resume() } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { print(cPlayerArr.count) return cPlayerArr.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "playercell", for: indexPath) as! CurrentPlayerCell let item = cPlayerArr[indexPath.row] cell.update(with: item) return cell }
Post
Replies
Boosts
Views
Activity
my text labels for example all have UILabel? nil. Part of my func update in the first question.Code 1: ImageControllerclass FetchImage {
func fetchItemArtwork(url: URL, completion: @escaping (UIImage?) -> Void) {
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data,
let image = UIImage(data: data) {
completion(image)
} else {
completion(nil)
}
}
task.resume()
}
}Code 2: CurrentPlayer classimport Foundation
struct CurrentPlayer: Codable, Hashable {
let photoUrl: URL
let firstName: String
let lastName: String
let positionCategory: String
let team: String
enum CodingKeys: String, CodingKey {
case photoUrl = "PhotoUrl"
case firstName = "FirstName"
case lastName = "LastName"
case positionCategory = "PositionCategory"
case team = "Team"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
photoUrl = try values.decode(URL.self, forKey: CodingKeys.photoUrl)
firstName = try values.decode(String.self, forKey: CodingKeys.firstName)
lastName = try values.decode(String.self, forKey: CodingKeys.lastName)
positionCategory = try values.decode(String.self, forKey: CodingKeys.positionCategory)
team = try values.decode(String.self, forKey: CodingKeys.team)
}
}
Yeah it's like a container view but without a childvc. I don't want the container to move when I scroll. I have a video of the issue but this site is not letting me post it.
The container view should not move it should be still like the text.
Yes I scroll the container view and I don't want that container to move. Is there any way I can upload images, I think that can make you understand better?
My child class is a container of my parent class and it contains a slider that moves a view that updates a label with a number.
Okay this is the code for one of my sliders in a child view. I want the calROA() method from the parent to be avaliable in the cAssMove function.
@IBAction func cAssMove(_ sender: Any) {
cAssetsHeight.constant = CGFloat(cAssetsSlider.value)
scaleCA = Int(6.75675675676 * cAssetsSlider.value)
cAssetsNum.text = "\(scaleCA)"
if scaleCA < 316 {
cAssetsLabel.text = ""
} else {
cAssetsLabel.text = "Current \n Assets"
}
}
It's in its own vc, I have 4 container viewcontrollers that are embedded in the parent. I'm gonna try notification and observer. I won't confuse view and viewcontroller again.
Yeah I was able to get it to work finally with notifications and observers. I made one of each for my calROA() method.
Okay so I should not have my stackviews be apart of a container.
I took my 2 stackviews out of the container but when I have vertical spacing with them to the text it collapses.
I defined constraints but when I increase the width of my freeform the lines get bigger and I lose one in my ui. How can I have a one size fits all?
Is there a way to make the intersection only at outside of the shape and not have it go inside?
I want it like this view is white black is tot ▭▬ not like this ❏ if that makes any sense. I don't want the labels overlapping.
Im wondering if there is a touch modifier I can add so that it touches tot but does not overlap it.