swfit-学习笔记(表UITableView的简单使用)

本文介绍了一个简单的Swift语言实现UITableView的例子,包括TableView的初始化、设置数据源和代理方法等关键步骤。

/*使用与Object-C基本类似,只做简单地使用,创建表及其设置数据源和代理*/

import UIKit 

 

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var _tableView = UITableView()    //声明全局变量

    override func viewDidLoad() {

        super.viewDidLoad()

        _tableView.frame = CGRectMake(0, 60, 320, 400)

        _tableView.delegate = self

        _tableView.dataSource = self

        _tableView.separatorStyle = UITableViewCellSeparatorStyle.None  //分隔线

        self.view.addSubview(_tableView)

        

    }

    //设置行数

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int

    {

        return 6;

    }

    //设置每行显示

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

    {

        var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")

   if !cell.isKindOfClass(UITableViewCell){

        //关于重用还没搞明白,不知道是不是应该这么判断

        }

        cell.accessoryType = UITableViewCellAccessoryType.DetailButton  //详细按钮

        cell.selectionStyle = UITableViewCellSelectionStyle.None    //是否能选中

        cell.textLabel?.text = "叼炸天!"

        return cell

    }

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

}

转载于:https://www.cnblogs.com/Zsmile/p/4200863.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值