ios - What is the right way (Best practice) for dequeue a reusable cell in swift 3? -
i'm want dequeue cell use in table view i'm afraid i'm doing in wrong way.
currently i'm doing way:
func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { guard let cell = tableview.dequeuereusablecell(withidentifier: "cellid", for: indexpath) as? customcell else { return uitableviewcell() } //configure atributes here. return cell }
what i'm want know if right or have check if cell nil?
var cell = tableview.dequeuereusablecell(withidentifier: "cellid", for: indexpath) customcell if cell == nil { cell = customcell() }
what code correct? if none of them right witch way right way?
just forced unwrap cell:
let cell = tableview.dequeuereusablecell(withidentifier: "cellid", for: indexpath) as! customcell ... return cell
since you have designed cell in interface builder crash reveal design error.
Comments
Post a Comment