下記のソースは
apiからデータを非同期通信で取得しているのですが、
6行目付近の"if(json["list]~)"の部分で、UIImage型の空配列をapiから取得したlistの
個数分用意して、そのあとの行で足して配列を増やす処理を行っています。
ですが、その処理が遅いせいか、後半の"self.banner.remove"のところでたまに
"index out of range"のエラーになってしまいます。。
できれば、この配列が用意されたら、非同期処理を行うようにしたいのですが、
それは可能でしょうか??
Alamofire.request("~api.php",method: .post, parameters: parameter).responseJSON { response in guard let object = response.result.value else{ return } let json = JSON(object) //apiで値が返ってくるまでは普通の処理 if(json["list"].count != 0){ let newBanner = [UIImage](repeating: UIImage(), count: json["list"].count) //配列の足し算 self.banner += newBanner } json["list"].forEach { (index, img_path) in self.race_date_time.append(img_path["date"].string!) Alamofire.request(img_path["img_path"].string!).responseImage { response in debugPrint(response.result) if let image = response.result.value { let imgratio:CGFloat = (image.size.height)/(image.size.width) let iw = CGFloat(self.sw) let resize = image.ResizeÜIImage(width: iw, height: iw*imgratio) self.BannerImage.append(img_path["img_path"].string!) self.banner.remove(at: json["list"].count * (self.scrollcount-1) + Int(index)!) self.banner.insert(resize!, at: json["list"].count * (self.scrollcount-1) + Int(index)!) } } } self.table.reloadData() }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/26 08:36
2018/06/26 08:40
2018/06/26 08:48
2018/06/26 09:00 編集
2018/06/26 09:00
2018/06/26 09:02
2018/06/26 09:08
2018/06/26 09:26 編集
2018/06/26 09:34
2018/06/26 09:40
2018/06/26 09:54 編集
2018/06/26 10:02
2018/06/26 10:04
2018/06/26 10:08
2018/06/26 10:11