Uitableview Swift tableview数据填充

Uitableview Swift tableview数据填充,uitableview,swift,Uitableview,Swift,在swift中只生成一个简单的Tableview,Tableview根本不填充任何内容。正在填充图像 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentifier = "cellIdentifier"; var cell: UITableViewCell? = tabl

在swift中只生成一个简单的Tableview,Tableview根本不填充任何内容。正在填充图像

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "cellIdentifier";
    var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell;

    if !(cell != nil){
        cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
            reuseIdentifier: cellIdentifier)

    }

    if(indexPath.row==0){
        cell!.textLabel.text = "POG Validation"
        cell!.imageView.image =  UIImage(named: "myImg")
    }

return cell;
cell!的框架!。text标签
为(0,0,0,0)。并且没有数据被填充

(lldb) po cell!.textLabel;

<UITableViewLabel: 0x7ce6c510; frame = (0 0; 0 0); userInteractionEnabled =  NO; layer = <_UILabelLayer: 0x7ce6c5d0>>
(lldb)采购订单单元格!。文本标签;

一旦我修复了您的编译错误,您的代码运行良好:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "cellIdentifier";
    var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell;

    if !(cell != nil){
        cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
            reuseIdentifier: cellIdentifier)

    }

    if(indexPath.row==0){
        // your forgot the '?'s
        cell!.textLabel?.text = "POG Validation"
        cell!.imageView?.image =  UIImage(named: "myImg")
    }

    return cell!; // you forgot the '!'
}
我会这样写:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "cellIdentifier";
    let dequedCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
    let cell = dequedCell ?? UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: cellIdentifier) as UITableViewCell

    if(indexPath.row==0){
        cell.textLabel?.text = "POG Validation"
        cell.imageView?.image = UIImage(named: "myImg")
    }

    return cell;
}

谢谢,我用和你一样的方法修好了。很抱歉这么晚才接受。:-)