2015-01-30 2 views
1

간단한 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!.textLabel의 프레임은 (0,0,0,0)입니다. 데이터가 채워지지 않습니다. 나는 당신의 컴파일 오류를 수정하면

(lldb) po cell!.textLabel; 

<UITableViewLabel: 0x7ce6c510; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ce6c5d0>> 

답변

1

, 당신의 코드는 잘 작동 :

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; 
} 
+0

감사합니다, 나는 당신과 동일한 방법에 대해 그것을 고정 . 늦게 받아들이 기 죄송합니다. :-) – CalZone

관련 문제