UITableView in Swift

前端 未结 17 1392
滥情空心
滥情空心 2020-12-04 08:09

I\'m struggling to figure out what\'s wrong with this code snippet. This is currently working in Objective-C, but in Swift this just crashes on the first line of the method.

17条回答
  •  遥遥无期
    2020-12-04 08:23

    Try this:

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
        cell.textLabel.text = "\(indexPath.row)"
    
        return cell
    }
    

    Note that you should register you UITableViewCell and ID when creating instantiating your UITableView:

    tableView.delegate = self
    tableView.dataSource = self
    tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
    

提交回复
热议问题