您的位置:首页 > 产品设计 > UI/UE

how to register a cell for UITableViewCell

2016-07-04 12:24 351 查看
storyboard method and api two methods: registerClass() and registerNib()

tableView.registerClass(FriendTableViewCell.self, forCellReuseIdentifier: NSStringFromClass(FriendTableViewCell))

tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: NSStringFromClass(UITableViewCell))

//default CellIndentifier is “UITableViewCell”, so NSStringFromClass(UITableViewCell) is “UITableViewCell”

tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: “DefaultCell”)

tableView.registerNib(UINib(nibName: “NibName”, bundle: nil), forCellReuseIdentifier: “CellFromNib”)// NibName is Xib file and this Xib must connect to a custom class ,for example StarTableViewCell

Use:

let cell = tableView.dequeueReusableCellWithIdentifier(NSStringFromClass(FriendTableViewCell), forIndexPath: indexPath) as! FriendTableViewCell

let cell = tableView.dequeueReusableCellWithIdentifier(“UITableViewCell”)! as UITableViewCell

let cell = tableView.dequeueReusableCellWithIdentifier(“DefaultCell”)! as UITableViewCell

let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:”Cell”)

var starCell: StarTableViewCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? StarTableViewCell
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: