2017-11-25 22 views
-3

私はtableViewにセルを追加しました。どのセルにも画像を表示したい私のクラス "MathViewController"に画像の配列を追加して、これらの画像をcell.butで表示しません。私の問題について知っている人はいませんか?私はあなたが私を助ければすばらしいだろう、私は非常に迅速です。 その私のクラスMathTableViewCellはストーリーボードから画像を取得する:TableViewCellはimageViewを表示しません

import UIKit 
class MathTableViewCell: UITableViewCell{ 

    @IBOutlet weak var imageCell: UIImageView! 
} 

、ここでは、クラスMathViewControllerです: :あなたはセル識別子がMathTableViewCellに設定されているよう

import UIKit 
class MathViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    @IBOutlet weak var tableController: UITableView! 

    let items = ["Calculatorimg" , "ss"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.tableController.register(UITableViewCell.self, forCellReuseIdentifier: "MathTableViewCell") 
     tableController.rowHeight = UITableViewAutomaticDimension 
     tableController.estimatedRowHeight = 44 
     tableController.delegate = self 
     tableController.dataSource = self 
    } 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return items.count 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     if let cell = tableView.dequeueReusableCell(withIdentifier: "MathTableViewCell", for: indexPath) as? MathTableViewCell{ 
      cell.imageCell.image = UIImage(named: items[indexPath.row]) 
      return cell 

     } 
     return UITableViewCell() 
    } 

} 

、ここでは私のストーリーボードですstoryboard

+0

これらの画像はアセットまたはフォルダ内にあります。これらの画像がフォルダ内にある場合、その画像の拡張子を "ss.png"のように指定する必要があります –

+0

@jitendraModi彼らはアセットにあります – nino

+0

項目[indexPath.row]を出力し、出力をチェックします。 –

答えて

-1

パート1:セル用に新しいXibを作成する場合。

全体コードは正確ですが、登録を忘れましたUITableViewCell NIBファイルをtableViewに貼り付けます。

ViewDidLoad

tableController.register(UINib(nibName: "MathTableViewCell", bundle: nil), forCellReuseIdentifier: "MathTableViewCell") 

パート2のコードの下に追加:クロスが正しいCellReuseIdentifierを確認してください。

+0

どうやってOPは余分なペン先を使用していますか? – vadian

+0

私はそれをしてエラーを受け取りました。名前が 'MathTableViewCell'のバンドルでNIBをロードできませんでした。 – nino

+0

はあなたの** CellReuseIdentifier ** = MathTableViewCellですか? –

関連する問題