2016-08-29 22 views
0

Swiftでスイッチを切り替えると、静的テーブルの行とセクションヘッダーを表示/非表示にしようとしています。私は行を非表示にすることができますが、1つのセクションヘッダービューを非表示にしようとすると、トグルを再びオンにするともう一方が消えていきます。私は何をしないのですSwiftで静的セクションヘッダーを非表示/表示する

@IBAction func toggleSound(sender: UISwitch) { 

    if(sender.on) { 
     self.sectionInVisible = false 


    } 
    else{ 
     self.sectionInVisible = true 
    } 


    let section = 1 

    let secPath = NSIndexPath(forRow: 1, inSection: 0) 
    self.tableView.cellForRowAtIndexPath(secPath)?.hidden = sectionInVisible 
    self.tableView.headerViewForSection(section)?.hidden = sectionInVisible 

    let numberOfRows = tableView.numberOfRowsInSection(section) 
    for row in 0..<numberOfRows { 
     let path = NSIndexPath(forRow: row, inSection: section) 
     tableView.cellForRowAtIndexPath(path)?.accessoryType = .None 
     tableView.cellForRowAtIndexPath(path)?.hidden = sectionInVisible 

    } 


    self.tableView.reloadData() 


} 

これは私のコードは次のようになりますか?私も高さを変更しようとしましたが、静的なテーブルでは機能しないと思います。

答えて

0

この種のものは間違っている:

self.tableView.cellForRowAtIndexPath(secPath)?.hidden = sectionInVisible 

行を削除する方法はdeleteRowsAtIndexPathsを呼び出すことです。セクションの場合も同様に、deleteSectionsコマンドがあります。

(セクションにはそれらのセクションがないように、またセクション全体が隠れている場合はセクションが存在しないように変更する必要があります。既に推測しているが、静的なテーブルでそれをするのに問題がある)

関連する問題