ios - Xcode Trigger Action after Cell is Clicked in Swift -


i relatively new programming in general (this first year learning @ school) please explain in easy way grasp possible.

i using uitableviewcontroller create table view , want able add string cell if empty (i think have add array "phrases", correct me if wrong) , display contents of cell if contains string. know has nsindexpath don't know put code.

class myphrases: uitableviewcontroller {  override func viewdidload() {     super.viewdidload() }  override func didreceivememorywarning() {     super.didreceivememorywarning()         }  var phrases = []  override func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return phrases.count }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell")!     cell.textlabel     return cell } 

}

sorry if messed formatting of code first question.

thanks in advance.

you correct, have declare array phrases strings:

var phrases = ["welcome stackoverflow", "second phrase", "third phrase"] 

and change cellforrowatindexpath method this:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell")!     cell.textlabel.text = phrases[indexpath.row]     return cell } 

index path describes position of cell in table view. has 2 important properties: row , section. since table view has 1 section, phrase display array row number.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -