swift - I'm getting in this program stack or it stops to work -
this program i'm beginner build succeeded running stop.
import uikit class viewcontroller: uiviewcontroller,uitableviewdelegate,uitableviewdatasource { var items = [string]() @iboutlet var textfield: uitextfield! @iboutlet weak var tableview: uitableview! @ibaction func addbutton(sender: uibutton) { let newitem = textfield.text items.append(newitem!) textfield.resignfirstresponder() } override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return items.count } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("cell",forindexpath: indexpath) cell.textlabel?.text = items[indexpath.row] cell.textlabel?.textcolor = uicolor.redcolor() return cell } }
the build succeeds, on running error in stack on flow showing 0 or nil can help?
i think missing tableview.reloaddata()
after adding newitem
datasource
try adding in ibaction this
@ibaction func addbutton(sender: uibutton) { let newitem = textfield.text items.append(newitem!) tableview.reloaddata() textfield.resignfirstresponder() }
Comments
Post a Comment