i'm new in swift programming . i'm trying features of textfield . want show textfields value in uitableview
. stuck in code please check out .... , give solution
import uikit class langviewcontroller: uiviewcontroller { var txt = "" let simpletableidentifier = "tableviewcell"; @iboutlet weak var txtlang: uitextfield! @iboutlet weak var langtableview: uitableview! override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() } @ibaction func addbuttontapped(sender: anyobject) { txt = txtlang.text self.langtableview.reloaddata() langdata.append(txt) print(langdata) txtlang.resignfirstresponder() } func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell! { let cell = tableview.dequeuereusablecellwithidentifier(simpletableidentifier) uitableviewcell cell.textlabel?.text = txt return cell; }
to update table view cells have call reloaddata()
. have this:
1. declare txt
variable right class definition starts:
var txt = ""
2. in button handler call reloaddata()
update cells.
@ibaction func addbuttontapped(sender: anyobject) { txt = txtlang.text self.tableview.reloaddata() }
3. set text cell's label:
func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell! { let cell = tableview.dequeuereusablecellwithidentifier(simpletableidentifier) as! uitableviewcell cell.textlabel?.text = txt return cell; }
Comments
Post a Comment