簡體   English   中英

NativeAd 的 IB Outlet 在 tableview 單元格中為零

[英]IB Outlet for NativeAd is nil in a tableview cell

  let nativeAdCell = tableView.dequeueReusableCell(
      withIdentifier: "Ads", for: indexPath) as! NativeAds

然后

 (nativeAdCell.HeadlineView).text = nativeAd.headline
        (nativeAdCell.PriceView).text = nativeAd.price
        

運行時,出現錯誤,說明 Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value。 這意味着視圖為零

編輯 1

   tableview.register(NativeAds.self, forCellReuseIdentifier: "Ads")


   let nativeAdCell = tableView.dequeueReusableCell(
       withIdentifier: "Ads", for: indexPath) as! NativeAds

我是如何注冊的,我為此使用了 Xib 文件

按照以下代碼在表格視圖中注冊 XIB 文件:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM