В моей функции cellForRowAtIndexPath
я установил URL-адрес для UIImageView для загрузки изображения. Когда это изображение загружено, я выбираю ячейку, а в didSelectRowWithIndexPath
изображение изображения ячейки равно нулю. На самом деле, даже метки - ноль. Все данные равны нулю, как будто в ячейке нет данных, но я мог ясно видеть ячейку визуально с данными, которые я хочу в ней.UIImageView.image ничто в моем UITableViewCell, когда я выбираю ячейку, хотя я знаю, что она должна иметь значение
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Session.sharedInstance.universities.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("universityCell", forIndexPath: indexPath) as! UniversityTableCell
if (indexPath.row < Session.sharedInstance.universities.count) {
let university = Session.sharedInstance.universities[indexPath.row]
cell.setInfo(university.imageUrl)
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.dequeueReusableCellWithIdentifier("universityCell", forIndexPath: indexPath) as! UniversityTableCell
// This is nil. But why? I set the data in my cellForRowAtIndexPath method
print(cell.universityImage.image)
}
В моей UniversityTableCell:
class UniversityTableCell: UITableViewCell {
@IBOutlet var universityImage: UIImageView!
func setInfo(url: String) {
self.universityImage.setImageWithURL(NSURL(string: url), usingActivityIndicatorStyle: .Gray)
}
override func prepareForReuse() {
super.prepareForReuse()
self.universityImage.sd_cancelCurrentImageLoad()
}
}