swif-表格(UITableView

2016-11-28  本文已影响0人  ysweiwei

表格(UITableView)

UITableView继承与UIScrollView

var tableView : UITableView? = nil
let frame = CGRect(x: 0, y: 0, width:          self.view.frame.size.width, height: self.view.frame.size.height)
   self.tableView = UITableView(frame: frame, style: .grouped)
self.tableView?.separatorColor = UIColor.red
       self.tableView?.separatorStyle = .singleLine
self.tableView?.delegate = self
        //代理:数据源
        self.tableView?.dataSource = self
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
        
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }

* 头部视图高度

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}

   
* 返回单元格(每个单元格走一次)reuseIdentifier: "1" :标志符

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{

    let cell = UITableViewCell(style: .value1, reuseIdentifier: "1")
    
    
    cell.imageView?.image = UIImage(named: "1.jpg")
    cell.textLabel?.text = "zhangsan"
    cell.detailTextLabel?.text = "简介"
     return cell     


 * //设置每一个单元格
 
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 100
}
上一篇 下一篇

猜你喜欢

热点阅读