2017-02-21 6 views
0

2人の異なる細胞を記入する方法を誰かが知っていますか?セルごとにenter image description here2つの異なる細胞を塗りつぶす方法は?

私は特定のクラス

import UIKit 

class MindCell: UITableViewCell { 

    @IBOutlet var textLabel1: UILabel! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(_ selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 

} 

class StepsMind: UITableViewCell { 

    @IBOutlet var number1Label: UILabel! 
    @IBOutlet var step1Label: UILabel! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(_ selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 

} 

を持っている。しかし、私は機能を設定する方法がわからない

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cellIdentifier = "Cell" 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell 

     // Configure the cell... 
     cell.textLabel1.text = "ABC" 

     return cell 
} 
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cellIdentifier1 = "MindCell" 
     let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind 

     // Configure the cell... 
     cell1.number1Label.text = "1" 
     cell1.step1Label.text = "DEF" 

     return cell1 
     } 

Xcodeは、それは同じで、2つのこれらの機能を使用することは不可能だと言います時間。私は何をする必要がありますか?

+0

使用するセルをどのように知っていますか?異なるテーブルビューまたは同じ?一意で同じfunc tableView(_ tableView:UITableView、cellForRowAt indexPath:IndexPath) - > UITableViewCell'の中で、どちらかを使用するようにテストします。 – Larme

+0

すべてのセルには独自の識別子 –

+1

がありますが、順序はindexPathです。 'MindCell'を表示し、' StepsMind'を表示するときの背後にあるロジックは何ですか? – Larme

答えて

0

コメントを見て、交互の行タイプが必要だと思います。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
    { 

    if indexPath.row % 2 == 0 
    { 
     let cellIdentifier = "Cell" 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MindCell 

     // Configure the cell... 
     cell.textLabel1.text = "ABC" 

     return cell 
    } 
    else 
    { 
     let cellIdentifier1 = "MindCell" 
     let cell1 = tableView.dequeueReusableCell(withIdentifier: cellIdentifier1, for: indexPath) as! StepsMind 

     // Configure the cell... 
     cell1.number1Label.text = "1" 
     cell1.step1Label.text = "DEF" 

     return cell1 

    } 

} 
+0

関数 'override func tableView(_ tableView:UITableView、numberOfRowsInSectionセクション:Int) - > Int { return 1 }のもう1つの問題があります。' 'return 1'は正常に動作しますが、1つのセルだけが表示されます' return 2'を設定した場合、プログラムは動作しません –

+0

@IuriiUshakovあなたが2を返すならば、 'if else'関連する行を与えるためのindexPath.section' – Honey

関連する問題