ios - different methods on one standard headCell in func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ -
i have 2 tableviews in same view controller: "studentstable" , "professorstable". wanted create standard head cell both tables. subclassed uitableviewcell , created headcell type. assigned 1 headcell both if indexpath.row==0. went smooth, however, there 1 problem. whenever click "addingbutton" want "addstudent" function called if on "studentstable" , "addprofessor" if on "professorstable". can create 2 headcells, 1 each of tables wonder if there more professional way of handling writing less code. here code suppose may work if right "if" condition given. in advance
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell{ var actiontype:string=string() if(/*what condition should put?*/) {actiontype="addstudent"} else {actiontype="addprofessor"} if(indexpath.row==0) { var theheadcell : headcell = tableview.dequeuereusablecellwithidentifier("headcell") headcell // cell setup if(actiontype != "") { addbutton.addtarget(self, action: nsselectorfromstring(actiontype), forcontrolevents: uicontrolevents.touchupinside) } return theheadcell } else { if (tableview==self.studentstable) { var cell : uitableviewcell = tableview.dequeuereusablecellwithidentifier("studentscell") uitableviewcell // cell setup return cell } else { var cell : uitableviewcell = tableview.dequeuereusablecellwithidentifier("professorscell") uitableviewcell // cell setup return cell } } }
if tableview == self.studentstable {actiontype = "addstudent"} else if tableview == self.professorstable {actiontype = "addprofessor"}
Comments
Post a Comment