ios - DynamicCastClassUnconditional with Custom Cell Class -


i want use custom cell class contains textfield. dynamiccastclassunconditional error each cell. how rid of error? , custom cell class correct?

table-class

import uikit  class settingsendpointcreateviewcontroller: uitableviewcontroller {  override func viewdidload() {     super.viewdidload()  }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: - table view data source  override func numberofsectionsintableview(tableview: uitableview) -> int {     // return number of sections.     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     // return number of rows in section.     return 3 }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell{      let cellid:string = "endpointname";     var cell:textcell = tableview.dequeuereusablecellwithidentifier(cellid) textcell;       return cell; }  @ibaction func returntoprevious(){     self.dismissviewcontrolleranimated(true, completion: nil); } } 

custom-cell-class

import uikit  class textcell: uitableviewcell {  var textfield:uitextfield = uitextfield(frame: cgrectmake(0, 0, 100, 100))  override func awakefromnib() {     super.awakefromnib()     // initialization code     addsubview(textfield)  }  override func setselected(selected: bool, animated: bool) {     super.setselected(selected, animated: animated)      // configure view selected state }  } 

you need register custom cell class table view reuse identifier. in view controller's viewdidload, add following:

class settingsendpointcreateviewcontroller: uitableviewcontroller {      override func viewdidload() {         super.viewdidload()         tableview.registerclass(textcell.self, forcellreuseidentifier: "endpointname")     }      // ... } 

also, note method you're using dequeue cell returns optional value. can either handle or call newer, non-optional returning method:

let cell = tableview.dequeuereusablecellwithidentifier(cellid, forindexpath: indexpath) textcell 

(finally, reuse identifier should constant set somewhere.)


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -