相关疑难解决方法(0)

自定义表格视图单元格:IBOutlet标签为零

考虑以下简单视图控制器:

class ViewController: UIViewController, UITableViewDataSource {
    @IBOutlet weak var tableView: UITableView!

    var items = ["One", "Two", "Three"]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "customCell")
        self.tableView.dataSource = self
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.items.count;
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("customCell") as CustomTableViewCell
        cell.titleLabel!.text = self.items[indexPath.row]
        return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

和自定义单元格视图:

class CustomTableViewCell: UITableViewCell {
    @IBOutlet weak var titleLabel: UILabel!   
}
Run Code Online (Sandbox Code Playgroud)

此代码导致以下错误.

致命错误:在展开Optional值时意外发现nil

titleLabel是零 - 不清楚为什么.设置 …

interface-builder uitableview ios swift

51
推荐指数
4
解决办法
4万
查看次数

如何在UICollectionView中添加节标题?

我的集合视图中的每个部分都需要一个标签.我试过简单地将标签拖到原型单元格上方的标题空间中,但每次运行应用程序时,标签都不可见.

有帮助吗?

ios swift

34
推荐指数
4
解决办法
3万
查看次数

标签 统计

ios ×2

swift ×2

interface-builder ×1

uitableview ×1