码迷,mamicode.com
首页 > 移动开发 > 详细

ios swift tableview

时间:2014-09-26 23:02:38      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

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

 

ios swift tableview

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/xyc20080413/p/3995695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!