ios - Swift: Adding UISegmentedControl/UITextField to dynamic UITableView -


i creating registration form application. app allows users create registration forms, , these registration forms displayed using uitableview. questions can either in form of text input (uitextfield) or multiple choice (uisegmentedcontrol). have question creation working, cannot figure out how display uitextfields , uisegmentedcontrols in uitableview. class use create question:

class question { var label: string var required: int  // create question init (label: string, required: int) {     self.label = label     self.required = required      if (self.required == 0) {         self.label = self.label + " *"     } }  }  class textinput: question { var placeholder: string  init (placeholder: string, label: string, required: int) {     self.placeholder = placeholder     super.init(label: label, required: required) } }  class multichoice: question { var answers: [string]  init(answers: [string], label: string, required: int) {     self.answers = answers     super.init(label: label, required: required) } } 

here current implementation of cellforrowatindexpath. have change display necessary contents.

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath)     cell.textlabel?.text = self.questionsarray[indexpath.row].label     return cell } 

one possible solution thinking of making uitextfield , uisegmentedcontrol class variables, created , initialized in class. however, still not know how display them. doubt there cell.textfield option. appreciated.

maybe should try:

  1. create 1 custom uitableviewcell uitextfield , other uisegmentedcontrol (don't forget create identifier each kind of cell)
  2. on cellforrowatindexpathindexpath, check if current question type textinput or multichoice , use appropriate identifier show right cell.

i hope helps


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -