iOS를 처음 사용합니다. 다음과 같이 cellForRowIndexPath 구현이 있습니다.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("ListCell")
if cell == nil {
let bundle = NSBundle(forClass: self.dynamicType)
tableView.registerNib(UINib(nibName: "Cell",bundle : nil), forCellReuseIdentifier : "ListCell")
cell = tableView.dequeueReusableCellWithIdentifier("ListCell")
}
(cell as? Cell)?.label.text = data[indexPath.row].name
return cell!
}
이 코드는 처음에는 작동했습니다. 실수로 자식 하드 리셋을 수행했습니다. 프로젝트 파일이 모두 엉망이되었습니다. 다른 문제를 수정했습니다. 경우에 따라 파일을 다시 추가합니다. 그러나 어떤 이유로이 코드는 현재 작동하지 않습니다. 프로젝트에 Cell.xib 파일이 있습니다.
오류는 '선언되지 않은 유형 셀 사용'입니다 .
(cell as? Cell)?.label.text = data[indexPath.row].name
이 문제를 어떻게 해결합니까?
미리 감사드립니다!
먼저 nib을 한 번만 등록하면 viewDidLoad
되므로이 코드를 귀하의 또는 tableView 에 넣으십시오 didSet
.
tableView.registerNib(UINib(nibName: "Cell",bundle : nil), forCellReuseIdentifier : "ListCell")
에서 cellForRow
코드를 다음과 같이 변경하십시오.
var cell: Cell = tableView.dequeueReusableCellWithIdentifier("ListCell") as! Cell
cell.label.text = data[indexPath.row].name
return cell
기본값 UITableViewCell
을 사용자 정의로 캐스팅하지 않았기 때문에 오류가 발생했습니다.Cell
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다