2017-03-07 1 views
1

을 닫지 않고 확장 테이블 뷰 셀 : https://www.youtube.com/watch?v=VWgr_wNtGPM,에 StackOverflow에 this answer에 의해 보충.스위프트 3 - 나는이 자습서 다음 봤는데 스위프트 3.</p> <p>를 사용하고 다른 사람

그러나이 방법은 내가 셀을 클릭하면 다른 셀을 숨기면서 확장됩니다. 내가 그것을 확장 할 때 이미 확장 된 다른 셀이 확장되도록 만드는 방법은 무엇입니까?

+0

검색어를 해결 했습니까? 그렇지 않다면 나는 이것으로 당신을 도울 것입니다. –

답변

0

을 가져 가라.

첫 번째 단계는 당신이 모델 목록을 작성해야이다는 같은 :

class CustomData { 
    var isExpanded: Bool = false; 
    // whatever other variables 
} 

다음 사용자 정의 셀이 원하는대로 보일 것입니다하지만 당신은 뭔가를 수행해야합니다 같은

var cellsData: [CustomData] = []; 

CustomData가 보인다 tableView:didSelectItemAt like :

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    let row = indexPath.row; 
    self.cellsData[row].isExpanded = !self.cellsData[row].isExpanded; 
    self.tableView.reloadRows(at: [indexPath], with: .none); // or the other animations 
} 

"tableView : cell "처럼 보인다 ForRowAt :

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell; 
    if(cell.isExpanded){ 
     // do something when the cell is expanded 
    }else{ 
     // do something when the cell is not expanded 
    } 
} 

기억, 셀은, 재사용 당신이 마지막으로 사용되었을 때 그 셀이 상태를 유지합니다, 한 시간보다 셀 더 사용한 경우 의미한다.

0

ExpyTableView을 사용하면 지정된 헤더 셀에서 확장 가능한 섹션을 만들 수 있습니다. iOS 8.0과 호환됩니다.

당신이 할 수있는 일은 다음 import ExpyTableView하고 있습니다 :

class ViewController: ExpyTableViewDataSource, ExpyTableViewDelegate { 

    @IBOutlet weak var expandableTableView: ExpyTableView! 

    // First, set data source and delegate for your table view. 
    override func viewDidLoad() { 
    super.viewDidLoad() 
    expandableTableView.dataSource = self 
    expandableTableView.delegate = self 
    } 

    // Then return your expandable cell instance from expandingCell data source method. 
    func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell { 
    // this cell will be displayed at IndexPath with section: section and row 0 
    } 
} 

당신은 당신의 전 테이블 뷰 섹션은 이제 확장 테이블 뷰 섹션 볼 수 있습니다. example project을 다운로드하고 자세한 예제를 볼 수도 있습니다.