uitableview - Swift - UITableViewCell? is not convertible to UITableViewCell -
i'm new swift development , following many online tutorials. majority of these tutorials referring older versions on xcode , code resulting in errors. can explain why code below produces 'uitableviewcell?' not convertible uitableviewcella , how go fixing problem.
i using xcode 7.
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("customcell") uitableviewcell cell.textlabel?.text = array[indexpath.item] return cell }
there 2 methods
1)
func dequeuereusablecellwithidentifier(_ identifier: string) -> uitableviewcell?
which returns optional have unwrap optional
let cell = tableview.dequeuereusablecellwithidentifier("custom cell")!
the other method preferable
2)
func dequeuereusablecellwithidentifier(_ identifier: string, forindexpath indexpath: nsindexpath) -> uitableviewcell
because returns non-optional
let cell = tableview.dequeuereusablecellwithidentifier("custom cell", forindexpath:indexpath)
Comments
Post a Comment