我在互联网上搜索了很多解决这个问题的办法,但我无法想象.我试图在表视图中创建一个自定义单元格.
我创建了一个CustomCell.swift类,以便在自定义单元格中配置我想要的标签,通过storyboard(tableview中的第一个原型单元格)创建它,并将其与标识符链接到cellForRowAtIndexPath方法
- override func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
- let cellIdentifier = "huisCell"
- var cell: CustomCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? CustomCell
- if cell == nil {
- cell = CustomCell(style: UITableViewCellStyle.Value1,reuseIdentifier: cellIdentifier)
- }
- cell!.huisAdresLabel.text = "123"
- cell!.huisDetailLabel.text = "456"
- return cell
- }
我的CustomCell.swift代码是这样的:
- class CustomCell: UITableViewCell {
- @IBOutlet var huisAdresLabel: UILabel
- @IBOutlet var huisDetailLabel: UILabel
- }
现在非常基础,但是我只是想让它工作,因为我可以扩展更多的属性和风格更好的单元格.
通过DropBox的图片,因为我需要10个声望来正确记录我的问题:)
https://www.dropbox.com/sh/5v9jb6cqp80knze/AAD5-yPR8-KoStQddkqKIbcUa
我希望有人可以解释我在做错什么
编辑:
要清除一些东西,在我尝试制作一个自定义单元格之前,我使用了基本的单元格,左边的一个标签.但是当我尝试对tableview进行风格化并创建一个自定义单元格时,它将无法正常工作.
另外,当测试不同的解决方案时,我遇到了CustomCell.swift中的两个标签为零的问题.即使我做了一个自定义的init,并且像一个
- self.huisAdresLabel = UILabel()
- <UILabel: 0xb2aadc0; frame = (0 -21; 42 21); text = '123'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0xb2aa3a0>>