なぜ私の配列が範囲外であるのかわかりません。私は、アレイ「imageArray」にフィード項目を入れて、それが私に致命的なエラーが発生しますHERESにコードindex out of bound swift
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! BlogPost
let blogPost: BlogPost = blogPosts[indexPath.row]
cell.textLabel?.text = blogPost.postTitle
// cell.textLabel?.text = blogPost.postImageLink
if cell.postImage?.image == nil {
// let cache = ImageLoadingWithCache()
// cache.getImage(self.postImageLink, imageView: cell.postImage, defaultImage: "IMG_0079")}
if cell.postImage?.image == nil {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
// retrieve image from url
let image = UIImage(data: NSData(contentsOfURL: NSURL(string:self.postImageLink)!)!)
self.imageArray.append(image!)
dispatch_async(dispatch_get_main_queue(), { Void in
// set image in main thread
cell.postImage?.image = self.imageArray[indexPath.row]
})
}
} else {
cell.postImage?.image = UIImage(named: "IMG_0079")
}
}
return cell
}
を、具体的にエラーがここに
cell.postImage?.image = self.imageArray[indexPath.row]
任意のアイデアですか?
この拡張機能を使用してみてください。UIImageView http://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift/27712427#27712427 –
私は 'indexPath'がクロージャが作成されたときにキャプチャされ、クロージャが呼び出されるときまでに 'indexPath.row'は古く、範囲外です。あなたがそこにたくさんの力を入れていることは言うまでもありませんが、それらのオプションのうちのいくつかが設定されていないとどうなりますか?テストして、正しくそれらをラップしてください! – ColGraff