2017-08-01 10 views
0

カスタムセルの3つのセクションでカスタムUItableviewを作成する方法を理解してください。iOSカスタムUItableviewcellセクション

  Sensor Info 
====================== 
Sensor 1: $Value_1 
Sensor 2: $Value_2 
Sensor 3: $Value_3 
Sensor 4: $Value_4 
Sensor 5: $Value_5 
Sensor 6: $Value_6 

      Errors 
=================== 
Error 1 : $error1 
Error 2..: $error2.. 

     Another Section 
======================== 
Error 1 : $error1 
Error 2..: $error2.. 

1つの提案は、1列にすべてのコンテンツを追加して、テーブルを移入するかもしれないが、私は別の後にロードするために、各セグメントを必要としています。各セグメントのコンテンツは、ボタンが押された後にビューコントローラクラス内のメソッドから生成されます。センサーの情報、エラー、別のセクションなど、後で追加する予定がある場合

私は、各セクションに異なる行の音節を持つテーブルを作成する方法を習得するのに苦労しています。私は、すべてのセンサーデータをカスタムセルにし、サブタイトルセルまたは正しい詳細を作りたいと思います。

+0

... –

答えて

1

テーブルに必要なソースとセクションの数を増やすことができます。

セクションごとにプロトタイプのセルを作成することもできます。

ちょうどあなたがどこにあるか確認し、同じようにそれを扱う:あなたはSTCollapseTableViewを試してみてくださいよりも、ライブラリと罰金している場合

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    return 44 
} 

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

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    if (section == 0) { 
     return "Title 1" 
    } 
    if (section == 1) { 
     return "Title 2" 
    }   
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    if section == 0 { 
     return contactPhones.count 
    } else if section == 1 { 
     return contactEmails.count 
    } else { 
     return 1 
    } 
} 

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cellIdentifier: String = "Cell" 
    var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as UITableViewCell! 
    if cell == nil { 
     cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: cellIdentifier) 
    } 

    if indexPath.section == 0 { 
     cell?.textLabel?.text = contactPhones[indexPath.row]["phoneNumber"].stringValue 
     cell?.imageView?.image = UIImage(flagImageWithCountryCode: contactPhones[indexPath.row]["phoneCountryCode"].stringValue) 
    } else if indexPath.section == 1 { 
     cell?.textLabel?.text = contactEmails[indexPath.row]["emailAddress"].stringValue 
    } 

    return cell! 
} 
+0

あなたは、このコードのObjective-Cのバージョンを持っていますか。私はまだ迅速に学ぶ必要があります。 – 3rdeye7

+0

テーブルビューのデリゲートメソッドは同じですが、その中の 'if'を処理して目標に到達する必要があります – GIJOW

+0

コードから判断すると、3つの異なるテーブルビューをstoryboardのviewcontrollerに追加しますか? – 3rdeye7

関連する問題