ios - Definition conflicts with a previous value after moving table functions into another function -


because of scope limit have socket.on("reply"), have move of table functions inside function addhandler()

as can see, func addhandler() inherit secondviewcontroller , 2 errors occur after move table functions

1) type secondviewcontroller not conform protocol 'uitableviewdatasource'

2) definition conflicts previous value (this part don't understand)

class secondviewcontroller: uiviewcontroller, uitableviewdatasource{//error 1  override func viewdidload() {     super.viewdidload()     print("second view loaded")     self.title = "ranking"      addhandler()     socket.connect()  }  func addhandler()->secondviewcontroller{     socket.on("reply") {data, ack in         let json = json(data)         print(json[0].count)         let pcount:int = json[0].count          func numberofsectionsintableview(tableview: uitableview) -> int {             return 1         }          func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {             //return data.count when data available server             return pcount         }          func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {//error 2             let cell = tableview.dequeuereusablecellwithidentifier("tablecell", forindexpath: indexpath) uitableviewcell              //everything refers             let patient = patientsample[indexpath.row] patient              if let celllist = cell.viewwithtag(100) as? uilabel{                 celllist.text = string(indexpath.row + 1)             }              //setting cell connection             if let sexicon = cell.viewwithtag(101) as? uiimageview{                 sexicon.image = self.gendericon(patient.ismale!)             }              if let namelabel = cell.viewwithtag(102) as? uilabel{                 namelabel.text = patient.name             }              if let scorelabel = cell.viewwithtag(103) as? uilabel{                 scorelabel.text = string(patient.score)             }             return cell         }          var i=0; i<pcount; ++i{             let patient = patient(id: json[0][i]["id"].intvalue, name: json[0][i]["name"].stringvalue, mileage: json[0][i]["mileage"].doublevalue)         }     }//end of function addhandler }    //gender icon func gendericon(ismale:bool) -> uiimage{     if ismale == true{         return uiimage(named: "boy")!     }else{         return uiimage(named: "girl")!     } }  override func didreceivememorywarning() {     super.didreceivememorywarning() } 

}

error #1: due fact class secondviewcontroller isn't implementing required methods needed when adopting uitableviewdatasource delegate. because scope of tableview methods unreachable.

error #2: in swift can't declare functions within functions have done.

take of tableview related methods out of addhandler() method.

if want tableview reload data when socket receives 'reply' message. use tableview.reloaddata().


Comments