Вот мой код, но я скопировал этот код во все классы контроллеров представления, поэтому просто пишу один из них здесь:
Код: Выделить всё
func refreshingphoto1() {
let firstImageURL = URL(string: "http://img.autobytel.com/car-reviews/autobytel/11694-good-looking-sports-cars/2016-Ford-Mustang-GT-burnout-red-tire-smoke.jpg")!
let session = URLSession(configuration: .default)
// Define a download task. The download task will download the contents of the URL as a Data object and then you can do what you wish with that data.
let downloadPicTask = session.dataTask(with: firstImageURL) { (data, response, error) in
// The download has finished.
if error != nil {
print("Error downloading picture")
self.firstImageJson.image = UIImage(named: "1.jpg")
} else {
// No errors found.
// It would be weird if we didn't have a response, so check for that too.
if (response as? HTTPURLResponse) != nil {
print("Downloaded picture with response code")
if let imageData = data {
// Finally convert that Data into an image and do what you wish with it.
let image = UIImage(data: imageData)
self.firstImageJson.image = image
// Do something with your image.
} else {
print("Couldn't get image: Image is nil")
self.firstImageJson.image = UIImage(named: "1.jpg")
}
} else {
print("Couldn't get response code for some reason")
self.firstImageJson.image = UIImage(named: "1.jpg")
}
}
}
downloadPicTask.resume()
}
}
Вот изображение моей раскадровки:
Как вы видите на рисунке, у меня есть страница VC2, которая является контроллером представления страницы, и четыре контроллера представления, подключенные к странице VC2:

Подробнее здесь: https://stackoverflow.com/questions/425 ... ers-in-pag