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

    }

相關文章
相關標籤/搜索