2017-09-27 1 views
0

저는 UITableView가 있고 스크롤하는 동안 저크를 생성하는 tableView의 "CellForRowAt"대리자 기능에 내 사용자 지정 UIView의 nib 파일을 포함합니다. 예 :스크롤하는 동안 저크를 생성하는 CellForRowAt에 사용자 지정 UIView 용 nib 파일 포함

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: 
     "cell", for: indexPath) as! CustomCell 
     let customView: CustomView = Bundle.main.loadNibNamed("CustomView", owner: 
     self, options: nil)![0] as! customView 
     cell.customViewPlacement.addSubview(customView) 
     return cell 
} 

어떻게하면 코드를 수정할 수 있습니까? 이것은 회원님이 셀을 만들고 기본적으로 새로운 뷰를 생성하는, 당신의 cellForRow에서 재사용 (중복 만들고 유지)마다 휴대 스크롤을 추가, 따라서 그것은 경련을 어떻게 감사

답변

0
cell.customViewPlacement.addSubview(customView) 

, 당신은 만들 필요가 휴대가 볼 펜촉과 같은 viewDidLoad에 펜촉 파일을 등록 :

tableView.register(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: "CustomCell") 

cellForRow 그냥 정상처럼 큐에서 :

let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell 
,536,

여러 종류의 셀이있는 경우 여러 개의 셀을 만들고 새로운 셀을 만들지 말고 현재 셀에 추가하십시오.

+0

아니요, 잘못되었습니다. tableViewCell의 펜촉을 만들지는 않습니다. customView는 셀에 배치 한 뷰입니다. let customView : CustomView = Bundle.main.loadNibNamed ("CustomView", 소유자 : 자기, 옵션 : 없음)! [0] as! customView // this is my customView ............ cell.customViewPlacement.addSubview (customView) // 여기 내 customView를 배치합니다. –

+0

그게 틀린 부분이라면, 당신이 말하는 뷰가있는 셀을 포함하는 펜촉을 만들고, 그것을 분리하지 말고, 어떤 이유로 든 할 수 없다면, 뷰를 'CustomCell' 클래스의' 'cellForRow'가 아니라'awakeFromNib' – Tj3n

관련 문제