首页 > 代码库 > ios swift tableview

ios swift tableview

import UIKitclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {@IBOutlet var myTable: UITableView?var typeArray:NSArray!override func viewDidLoad() {    super.viewDidLoad()    typeArray = ["onet", "two", "three", "four"];}func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{return typeArray.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 = string    return cell} 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 that can be recreated.}}

 

ios swift tableview