2017-05-02 14 views
0

私はこのサイトを精査して問題を解決しています。私は1つを見つけましたが、コードによって何らかの理由で意図した通りに動作しません。私の目標は、その中のセクションを持つテーブルビューを持つことです。各セクションの下には、各セクションの異なる量(1つのセクションに1つと他のセクションに3つのセルなど)があります。ここでそれぞれの細胞の量が異なるセクションを作る方法

は私のコードは私の目標は、2つのdiffferentヘッダを持つことで、テストおよびtesttt

テストはタイトルこのサブタイトル情報1で細胞を持っているので、

になります

import UIKit 

class cat1: UIViewController, UITableViewDelegate, UITableViewDataSource { 

let proc = [["this"], ["Ye", "it", "will"]] 

let infor = [["info 1"] , ["info 3", "info 2" , "info 4"]] 
let arrayforsec = [ "test", "testtt"] 


override func viewDidLoad() { 


    super.viewDidLoad() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
     } 



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     return proc[section].count 
      } 



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


    let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as UITableViewCell 
    let cellText = proc[indexPath.section][indexPath.row] 
    let descriptiontxt = infor[indexPath.section][indexPath.row] 


    cell.detailTextLabel?.numberOfLines = 0 
    cell.detailTextLabel?.lineBreakMode = .byWordWrapping 

    cell.textLabel?.text = cellText 
    cell.detailTextLabel?.text = descriptiontxt 

    return (cell) 
} 

func tableView(_ tableView: UITableView, titleForHeaderInSection section :Int) -> String?{ 
       return arrayforsec[section] 



     } 


func numberOfSectionsInTableView(in tableView: UITableView) -> Int { 

    return proc.count 
} 

} 

です

何がうんざりですか?ここ

は、私が相談のソリューションです:How do I populate two sections in a tableview with two different arrays using swift?

(/ 40 upvotes W応答)

+0

'UITableViewDataSource'または' UITableViewDelegate'メソッドのいずれかが呼び出されていますか? – AdamPro13

+0

はい、私はそうだと思うので、テーブルは最初のセクションとセルだけを読み込みます。セクションとして "test"、 "description"として "info 1"、残りはちょうど表示されません... –

+0

@GaryMakin that's彼が 'UITableViewController'を使うのではなく、' UITableView'をビューコントローラのサブビューとして追加した場合は真です。 – AdamPro13

答えて

1

あなたは間違っている関数の名前を持っています。

func numberOfSections(in tableView: UITableView) -> Int { 
    return proc.count 
} 

これは、参照していた質問より新しいバージョンのSwiftで名前が変更されました。 Swiftは定期的に変更されているので、関数とシンボルの名前を二重にチェックする価値があります。

+0

はいそれです!あまりにもありがとう、私は頭がおかしくなってから私を救った –

関連する問題