ios swift tableview

import UIKit

class 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.
}
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。