Swift_ uitableview使用自定义cell

uitableview 使用 xib 的自定义cell swift

新建cell:(假如命名 MyCell)
ui

使用:spa

向 tableview 注册 nibit

全局变量 let cellIdentifier = "myCell"table

myTableView!.registerNib(UINib(nibName: "MyCell", bundle:nil), forCellReuseIdentifier: cellIdentifier)变量

而后在 cellForRowAtIndexPath 方法中使用:uitableview

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

        // 系统 cell 的简单用法方法

        //let cell = UITableViewCell(style:.Default, reuseIdentifier:"myCell")im

        //cell.textLabel.text = "swift cell \(indexPath.row)"

           

        var mycell : MyCell = tableView!.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as MyCell

        return mycell

    }

相关文章
相关标签/搜索