Vote count:
0
Im trying to write a Swift iOS application that displays one of four images based on the outcome of a API JSON Response.
I have 4 images in the Xcode project, defined as:
let crossStatus: UIImage = UIImage(named:"cross-circle")!;
let exclamationStatus: UIImage = UIImage(named:"exclamation")!;
let informationStatus: UIImage = UIImage(named:"information")!;
let tickStatus: UIImage = UIImage(named:"tick-circle")!;
The app makes an API request and gets back JSON of:
services{current-events{id: "up", image: "image.url.location"}}
I have services as an NSDictionary and current-events as another inside that, when I make a NSURL out of 'image' and pop the NSURL into the cell the page works as expected, but I want to be able to load the local images pending the response of 'id'.
The code for the IF is:
let statusID = rowData["id"] as? String;
let imgData : UIImage = crossStatus;
if (statusID == "up") {
let imgData : UIImage = tickStatus;
}
if (statusID == "warning") {
let imgData : UIImage = exclamationStatus;
}
if (statusID == "down") {
let imgData : UIImage = crossStatus;
}
else {
let imgData : UIImage = exclamationStatus;
}
When I run the code now, the crossStatus image is called but 90% of the services are either up or warning, so I know the placeholder is working but now the changing of the variable.
Where am I going wrong? Thanks Mathew
Swift Assign Image If string == 'Something'
Aucun commentaire:
Enregistrer un commentaire