2017-11-03 9 views
2

私はXcodeでカスタムセルのビューを作成しました:カスタムUITableViewCellの表示されていないラベル

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell 

     let iniStr = self.tableArray[indexPath.row] 

     let fullNameArr = iniStr.components(separatedBy: "||1||") 
     let daFirst = fullNameArr[0] 
     let daSecond = fullNameArr[1] 

     let finalco = daSecond.components(separatedBy: "||2||") 
     let fString = finalco[0] 

     cell.questionLabel?.text = daFirst 
     cell.answerLabel?.text = daSecond 

     return cell 
    } 

class FeedCell: UITableViewCell { 

    @IBOutlet weak var questionLabel: UILabel! 
    @IBOutlet weak var answerLabel: UILabel! 

} 

はその後、ストーリーボードのすべてをフックアップ、制約を設定し、登録されたクラス:self.tableView.register(FeedCell.self, forCellReuseIdentifier: "Cell")

は、私はクラスとして字幕を使用する場合私のカスタムテーブルのセルはすべて正常に動作しますが、私のテーブルセルでカスタムFeedCellを使用すると、ラベルは表示されませんが、セルを選択できます。

+0

あなたは 'FeedCell'用に別のXIBファイルを作成したデバッグ接続にこのコードを試してみてください?あなたはあなたの質問でストーリーボードを述べているので、私は、セルのUIがコントローラの中に直接配置されていると推測しています。その場合、 'self.tableView.register'を呼び出す必要はありません。 –

+0

@ØyvindHaugeいいえ、私は作成されていない、私はどのようにするか分からない。 – Scripy

+0

UITableViewDataSourceに確認されているかどうかを確認して、numberofRowsInSectionが正しい行番号を返すかどうかを確認します。 – suhit

答えて

1

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedCell 

     let iniStr = self.tableArray[indexPath.row] 
     print(iniStr) 

     let fullNameArr = iniStr.components(separatedBy: "||1||") 
     let daFirst = fullNameArr[0] 
     let daSecond = fullNameArr[1] 
     print(daFirst) 
     print(daSecond) 

     let finalco = daSecond.components(separatedBy: "||2||") 
     let fString = finalco[0] 

     cell.questionLabel?.text = daFirst 
     cell.answerLabel?.text = daSecond 

     cell.questionLabel.backgroundColor = .red 
     cell.answerLabel.backgroundColor = .green 




     return cell 

    } 
+0

とは何ですか? – Scripy

+0

xibカスタムセルの名前。 –

+0

OPは、彼が "ストーリーボードのすべてをフックした"と言います。これは、自分のカスタムセルに別のレイアウトファイルを使用していないことを意味します。従って、「レジスタ」は不要である。 –

関連する問題