ImportUIKitclassViewcontroller:uiviewcontroller, Uitableviewdelegate, Uitableviewdatasource {@IBOutlet var mytable:uitableview ?var typearray:nsarray!override func Viewdidload () {Super. Viewdidload () Typearray= ["Onet", "I", "three", "four"];} Func TableView (Tableview:uitableview!, Numberofrowsinsection Section:int)int{returntypearray.count}func TableView (Tableview:uitableview!, Cellforrowatindexpath indexpath:nsindexpath!) uitableviewcell!{Let identifier= "Cellidentifier"var Cell:uitableviewcell? = Tableview.dequeuereusablecellwithidentifier (identifier) as?UITableViewCell Cell=UITableViewCell (style:. Default, Reuseidentifier:identifier) var string:string=Typearray[indexpath.row] as String cell!. Textlabel.text =stringreturnCell} func tableView (Tableview:uitableview!, Didselectrowatindexpath indexpath:nsindexpath!) {var alert= Uialertcontroller (title: "Alert", Message: "You have selected \ (indexpath.row) Row", PreferredStyle:UIAlertControllerStyle.Alert) alert.addaction (uialertaction (title:"OK", Style:UIAlertActionStyle.Default, Handler:nil)) Self.presentviewcontroller (Alert, animated:true, Completion:nil)} Override Func didreceivememorywarning () {Super. didreceivememorywarning ()//Dispose of any resources the can be recreated.}}
iOS Swift TableView