相关疑难解决方法(0)

Swift中的简单UITableView - 意外地发现没有

非常简单的代码:

func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
    return 1
}

func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {
    return 5
}


func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {
    let cell: BookTableViewCell = BookTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "BookCell")
    println("ip: \(indexPath.row)")
    cell.bookLabel.text = "test"

    return cell
}
Run Code Online (Sandbox Code Playgroud)

在cell.bookLabel.text行我得到这个:

fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)

BookTableViewCell的定义如下:

class BookTableViewCell: UITableViewCell {

    @IBOutlet var bookLabel: UILabel

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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

标签 统计

ios ×1

swift ×1

uitableview ×1