ios - Prevent selected cell from being reused -
so have tableview has list of items in each cell. each of these cells contain image view which, upon being tapped, expands cell , displays image item. when scroll down table view , scroll cell selected, image gone. know due reusing cells i'm not sure on how keep expanded cells image in place while scrolling through other items.
the closest i've come here: my table view reuse selected cells when scroll -- in swift
if lend me hand awesome. thanks!
edit: adding code snippets - sorry wait.
fileprivate var expandedrowindex: int? // cellforrowat func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { // catalogitem row. let item = self.items[indexpath.row] let expanded = indexpath.row == self.expandeditemrowindex // return standard catalog item cell. let reuseid = expanded ? catalogitemcell.protocell_expanded.id : catalogitemcell.protocell.id let cell = tableview.dequeuereusablecell(withidentifier: reuseid) as! catalogitemcell // reset thumbnail image nil. needed images appear // in cell belong in. if indexpath.row == self.expandedrowindex{ cell.uiimage_thumbnail.image = nil } return cell } // didselectrowat func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) { tableview.deselectrow(at: indexpath indexpath, animated: true) // expand row - current cell , show image self.expandeditemrowindex = indexpath.row let item = self.items[indexpath.row] let currentcell = tableview.cellforrow(at: indexpath) // pass both selected cell , item imagemanager imagemanager.startimagerequest(currentcell: currentcell!, item: item) if self.expandedrowindex == indexpath.row { // selected row expanded. return } var reloadpaths = [indexpath]() // collapse expanded row. if let previousrowindex = self.expandedrowindex { reloadpaths.append(indexpath(row: previousrowindex, section: 0)) } // expand selected row. self.expandedrowindex = indexpath.row let item = self.items[indexpath.row] debugprint(item.description) reloadpaths.append(indexpath(row: indexpath.row, section: 0)) tableview.reloadrows(at: reloadpaths [indexpath], with: .fade) }
you can maintain selectedindex variable. in cellforrow check whether call selectedcell. if yes, customisation required selected cell.
also might want handle heightforrow, there check whether call selected cell.
you can maintain indexpath selected cell. if there multiple sections. no need prevent getting reused.
hope helps.
Comments
Post a Comment