Когда я выбираю ячейку в UITableView
, я меняю свое изображение, но меняет камеру из поля зрения (нужно прокрутить вниз, чтобы увидеть затронутую ячейку), что означает, что затронутая ячейка также измените его изображение. Это должно быть что-то о повторно используемых ячейках, но я не могу понять, почему и как решить эту проблему. Надеюсь, вы, ребята, можете мне помочь, спасибо.Выбор ячейки в UITableView влияет на другой.
Другое дело, что ячейка не должна сбрасывать свое изображение, когда он получает прокрутку с глаз долой.
Вот мои делегаты для UITableView
:
//UITableview delegate
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Arecipe.IngredientArr.count
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if (tableView == IngrediensTableView) {
print("Cell")
var cell = tableView.dequeueReusableCellWithIdentifier("Cell")
let ingredient = self.Arecipe.IngredientArr[indexPath.row]
if ((cell == nil)) {
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
cell!.imageView?.image = UIImage(named: "Ingr_Uncheck")
}
cell!.textLabel?.text = ingredient.UnitValue + " " + ingredient.UnitName + " " + ingredient.Name
cell!.selectionStyle = .None
return cell!
}
return UITableViewCell()
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Row \(indexPath.row) selected")
if (tableView == IngrediensTableView) {
let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
print(cell.textLabel?.text)
if(cell.imageView?.image == UIImage(named: "Ingr_Uncheck")) {
cell.imageView?.image = UIImage(named: "Ingr_Check")
} else {
cell.imageView?.image = UIImage(named: "Ingr_Uncheck")
}
}
}
я была аналогичная проблема с этим. .if раз вам нужно увидеть NSCache, если вы не используете эту библиотеку «sdwebimage» .. это сделает все для вас ... сохраняя все изображения в каталоге документа и повторно используя его ... –