基于swift的UItableview

前端之家收集整理的这篇文章主要介绍了基于swift的UItableview前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import UIKit

class ViewController: UIViewController@H_403_3@,UITableViewDataSource@H_403_3@,UITableViewDelegate@H_403_3@ {

    var tableview :UITableView@H_403_3@!
    var cellarray :NSMutableArray@H_403_3@!
    overridefunc viewDidLoad() {
        super@H_403_3@.viewDidLoad@H_403_3@()
        // Do any additional setup after loading the view,typically from a nib.@H_403_3@

        self@H_403_3@.cellarray@H_403_3@ = ["1"@H_403_3@,"2"@H_403_3@,"3"@H_403_3@,"4"@H_403_3@,"5"@H_403_3@,"6"@H_403_3@,"7"@H_403_3@,"8"@H_403_3@,"9"@H_403_3@,"10"@H_403_3@]
        tableViewSubView()

    }
    func tableViewSubView()
    {
        self@H_403_3@.tableview@H_403_3@ =UITableView@H_403_3@(frame: self@H_403_3@.view@H_403_3@!.frame@H_403_3@,style:UITableViewStyle.Plain@H_403_3@)
        self@H_403_3@.tableview@H_403_3@?.dataSource@H_403_3@ =self@H_403_3@;
        self@H_403_3@.tableview@H_403_3@!.delegate@H_403_3@ =self@H_403_3@;

        self@H_403_3@.view@H_403_3@!.addSubview@H_403_3@(self@H_403_3@.tableview@H_403_3@!)
    }

    // 数据源方法,返回多少组@H_403_3@
    func numberOfSectionsInTableView(tableView:UITableView@H_403_3@) -> Int {
        return1;
    }

    // 每组有多少行@H_403_3@
    func tableView(tableView:UITableView@H_403_3@,numberOfRowsInSection section:Int) -> Int {
        returnself.cellarray@H_403_3@.count@H_403_3@;
    }

    // 每行展示什么内容@H_403_3@
    func tableView(tableView:UITableView@H_403_3@,cellForRowAtIndexPath indexPath:NSIndexPath@H_403_3@) -> UITableViewCell@H_403_3@ {

        var cell=tableView.dequeueReusableCellWithIdentifier@H_403_3@("reuse"@H_403_3@)as? UITableViewCell@H_403_3@

        if@H_403_3@ (cell==nil@H_403_3@){

            cell=UITableViewCell@H_403_3@(style: .Default@H_403_3@,reuseIdentifier:"reuse"@H_403_3@)

        }

        // cell!.textLabel!.text="\(indexPath.row)"@H_403_3@
        cell?.textLabel@H_403_3@?.text@H_403_3@ = self@H_403_3@.cellarray@H_403_3@[indexPath.row@H_403_3@]as? String

        return@H_403_3@ cell!

    }

    overridefunc didReceiveMemoryWarning() {
        super@H_403_3@.didReceiveMemoryWarning@H_403_3@()
        // Dispose of any resources that can be recreated.@H_403_3@
    }


}

猜你在找的Swift相关文章