"ExperienceScreen"と呼ばれるメインのViewControllerにロードされたxibファイルでビューを作成しました。このxibビューをExperienceScreenに追加すると、完全に機能します。問題は、このxibビューをUITableViewCelに追加したいということです。私はそれを行うために次のコードを使用しています:UITableViewセルにxibビューを表示
let experiences = service.getExperiences()
// 3. Loop through the array of experiences
for element in experiences {
if let customView = Bundle.main.loadNibNamed("ExperienceDetail", owner: self, options: nil)?.first as? ExperienceDetail
{
customView.lblTitle.text = element.title
customView.lblCompany.text = element.company
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
cell.addSubview(customView)
cell.bringSubview(toFront: customView)
}
}
tableView.reloadData()
起動時に、サブビューはUITableViewCellに表示されません。 カスタムビュービューがxibビューで正しく埋められています。私はブレークポイントを使ってこれをチェックしました。
私が間違っていることを誰かが知っていますか?
助けてくれてありがとうございました!
はお返事をありがとうを登録!残念ながらそれはまだ表示されません。自分のコードに問題が表示されますか: https://www.dropbox.com/s/zr2eknaeovks381/Experiences.swift?dl=0 https://www.dropbox.com/s/op6kg8a4eh2u0i0/ExperienceDetail.swift ?dl = 0 –
cellForRowAtでの変更 let cell = tableView.dequeueReusableCell(withIdentifier: "cell")! UITableViewCellとして cell = tableView.dequeueReusableCell(withIdentifier:ExperienceDetail.identifier)を! ExperienceDetail あなたの必要性に応じてtableCellを設定してください –
素晴らしいおかげさま!!!! –