In meiner App habe ich tableview
mit Abschnitten. Das Problem ist mit Bildern. Wenn der Benutzer die Liste scrollt, sind die angezeigten Bilder nicht korrekt. Ich weiß, dass das Problem wegen der Wiederverwertung ist, aber ich kann immer noch keine Lösung finden.Bilder nicht korrekt angezeigt, wenn gescrollt iOS Swift
-Code
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myeventCell = self.tableView.dequeueReusableCellWithIdentifier("MyEventsTableViewCell", forIndexPath: indexPath) as! MyEventsTableViewCell
myeventCell.wedImage.clipsToBounds=true;
myeventCell.tag=indexPath.row+indexPath.section;
//to download image
if wedImgDownload[indexPath.section][indexPath.row] == false
{
// myeventCell.wedImage.image = UIImage(data: self.webImgData[indexPath.section][indexPath.row]);
if let url = NSURL(string: wedImageUrl[indexPath.section][indexPath.row] as String) {
let request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
(response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in
if let imageData = data as NSData? {
if myeventCell.tag == indexPath.row+indexPath.section {
self.wedImgDownload[indexPath.section].removeAtIndex(indexPath.row)
self.wedImgDownload[indexPath.section].insert(true, atIndex: indexPath.row)
self.webImgData[indexPath.section].insert(data!, atIndex: indexPath.row)
myeventCell.wedImage.image = UIImage(data: imageData);
}
}
}
}
}
else{
if self.webImgData[indexPath.section][indexPath.row] != ""{
if myeventCell.tag == indexPath.row+indexPath.section {
myeventCell.wedImage.image = UIImage(data: self.webImgData[indexPath.section][indexPath.row])
}
}
}
return myeventCell;
}
Bitte lass mich wissen, wie dieses Problem zu lösen?
Gibt es einen Grund, warum Sie 'NSURLConnection' verwenden? Kannst du 'NSURLSession' oder etwas Open Source wie Alamofire nicht benutzen? – dokun1
Nein ich möchte nicht Bibliothek verwenden –