2017-12-05 4 views
0

最初のコードは、リンクされた画像に添付された最初のビューコントローラを担当しています。ユーザーが次のビューにプッシュできるコメント付きのビットを追加するまではうまく動作し、選択されたyearOfStudy写真のようにFEEYear3をタップすると、それぞれのコースの下でその研究年度の単位が表示されます。私がコメントを外すと、「タイプ 'Section'の値を期待される引数タイプ 'String'に変換できません」というエラーが表示されます。私は、セクションの下に 'セクション'は、構造体として設定されていることを追加する必要があります。 「細胞:これに応じて、それに応じて、様々なstudyYearsの単位を表示する第2のViewControllerの機能はIを書き込むライン上のエラーを取得選択される有する第2コードでerrors: 'Section'型の値を期待される引数型 'String'に変換できません。 'string'型の値を 'string'に割り当てることはできません。

import UIKit 

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, ExpandableHeaderViewDelegate{ 

    @IBOutlet var tableView: UITableView! 

    var sections=[ 

     Section (courses: "Electrical Engineering", 
       yearOfStudy:["FEEYear1","FEEYear2","FEEYear3","FEEYear4","FEEYear5"], 
       expanded: false), 

     Section (courses: "Civil Engineering", 
       yearOfStudy:["FCEYear1","FCEYear2","FCEYear3","FCEYear4","FCEYear5"], 
       expanded: false), 


     Section (courses: "Geospatial Engineering", 
       yearOfStudy:["FGEYear1","FGEYear2","FGEYear3","FGEYear4","FGEYear5"], 
       expanded: false), 

     Section (courses: "Mechanical Engineering", 
       yearOfStudy:["FMEYear1","FMEYear2","FMEYear3","FMEYear4","FMEYear5"], 
       expanded: false), 

     Section (courses: "Biosystems Engineering", 
       yearOfStudy:["FBEYear1","FBEYear2","FBEYear3","FBEYear4","FBEYear5"], 
       expanded: false) 
    ] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

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

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return sections[section].yearOfStudy.count 
    } 

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
     return 44 
    } 

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     if (sections[indexPath.section].expanded){return 44} 
     else{return 0} 
    } 

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
     return 2 
    } 

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
     let header=ExpandableHeaderView() 
     header.customInit(title: sections[section].courses, section: section, delegate: self) 
     return header 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell")! 
     cell.textLabel?.text = sections[indexPath.section].yearOfStudy[indexPath.row] 
     return cell 
    } 

    func toggleSection(header: ExpandableHeaderView, section: Int) { 
     sections[section].expanded = !sections[section].expanded 
     tableView.beginUpdates() 
     for i in 0..<sections[section].yearOfStudy.count{ 
      tableView.reloadRows(at: [IndexPath(row:i,section:section)], with: .automatic) 
     } 
     tableView.endUpdates() 
    } 

/* func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     let unitsVC = UnitsVC() 
     unitsVC.customInit(sectionsIndex: indexPath.row, title: sections[indexPath.row]) 
     self.navigationController?.pushViewController(unitsVC, animated: true) 
     tableView.deselectRow(at: indexPath, animated: true) 
    } 
    */ 
} 

The image is for the first page of my project app

。 textLabel?.text = unitsData [sectionsIndex] [indexPath.row] " "文字列 '[string]'の値を 'string'に割り当てることはできません。 "これらのエラーを取り除くにはどうすればよいですか?

import UIKit 

class UnitsVC: UIViewController, UITableViewDataSource, UITableViewDelegate { 

    @IBOutlet var tableView: UITableView! 


    let unitsData = [ 
     [["fee101","fee111","fee121","fee131","fee141","fee151","fee161","fee102","fee112","fee122","fee132","fee142","fee152","fee162"],["fee201","fee221","fee231","fee241","fee251","fee261","fee271","fee281","fee202","fee222","fee232","fee242","fee252","fee262","fee272","fee282"],["fee301","fee321","fee331","fee341","fee351","fee361","fee371","fee381","fee302","fee322","fee332","fee342","fee352","fee362","fee372","fee382"],["fee401","fee411","fee421","fee431","fee441","fee451","fee471","fee481","fee402","fee412","fee422","fee432","fee442","fee452","fee472","fee482"],["fee501","fee511","fee521","fee531","fee541","fee551","fee560","fee571","fee591","fee502","fee512","fee522","fee532","fee542","fee552","fee560","fee582","fee592"]], 

     [["fce101","fce131","fce161","fce163","fce165","fce181","fce103","fce132","fce162","fce164","fce166","fce182"], 
     ["fce201","fce231","fce211","fce245","fce251","fce261","fce265","fce232","fce242","fce222","fce246","fce262","fce272"], 
     ["fce301","fce311","fce321","fce331","fce341","fce351","fce361","fce302","fce312","fce322","fce332","fce342","fce352","fce362","fce392"], 
     ["fce401","fce411","fce421","fce425","fce431","fce451","fce461","fce481","fce402","fce412","fce422","fce426","fce432","fce446","fce472"], 
     ["fce581","fce511","fce525","fce531","fce545","fce571","fce564","fce590","fce512","fce526","fce532","fce572","fce552"]], 

     [["fme169","fme111","fme151","fme161","fme171","fme173","fme112","fme152","fme165","fme166","fme167","fme168","fme172","fme174","fme182"],["fme201","fme211","fme251","fme261","fme271","fme281","fme291","fme202","fme212","fme222","fme244","fme252","fme262","fme272"],["fme301","fme311","fme321","fme331","fme343","fme351","fme371","fme363","fme391","fme302","fme312","fme322","fme332","fme344","fme352","fme362","fme372"],["fme411","fme431","fme432","fme452","fme471","fme472","fme492","fme401","fme421","fme422","fme441","fme442","fme461","fme462"],["fme511","fme521","fme531","fme541","fme551","fme561","fme581","fme502","fme503","fme504","fme513","fme523","fme524","fme525","fme533","fme524","fme542","fme543","fme544","fme545","fme552"]] 

    ] 

    var sectionsIndex: Int! 


    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.tableView.dataSource = self 
     self.tableView.delegate = self 

     let nib = UINib(nibName:"UnitsCell", bundle: nil) 
     tableView.register(nib, forCellReuseIdentifier: "unitsCell") 

     // Do any additional setup after loading the view. 
    } 

    func customInit(sectionsIndex:Int, title: String) { 

     self.sectionsIndex=sectionsIndex 
     self.title=title//attribute for navigation controller bar 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return unitsData[sectionsIndex].count 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "unitsCell", for: indexPath) as! UnitsCell 
     cell.textLabel?.text = unitsData[sectionsIndex][indexPath.row]//line with error 
     return cell 

    } 

答えて

0

あなたは配列の配列を持っているようです。あなたのイメージに基づいて、電気工学から3年目を選択したいとしましょう。

(あなたは追加のコードを提供しなかったので、私はこの答えをあなたの使用してテーブルビューのセクションを想定しています。)

を年間3をつかむために、あなたは私が持っている、let year3Data = unitsData[0][2]

+0

ねえ、DookieManのように単純にアクセスすることになり質問を完全に再構築しました...見てみましょう、あなたが助けることができるかどうかを見てください、私はあなたの以前の提案を決して掴んだことはありません –

関連する問題