2017-01-13 3 views
0
let indexPaths = (0..<array.count - 1).map { i in 
    return IndexPath(item: i, section: section) 
} 

tableView.beginUpdates() 
if hidden[section] { 
    array.remove(at: IndexPath(item: item, section: section).row) 
    tableView.deleteRows(at: indexPaths, with: .fade) 
} else { 
    tableView.insertRows(at: indexPaths, with: .fade) 
} 
tableView.endUpdates() 

해당 섹션의 헤더가 탭될 때 UITableView에서 섹션의 모든 셀을 삭제하려고합니다. 그러나 올바르게 작동하지 않는 것 같습니다.Swift에서 UITableView의 행을 삭제하는 방법

오류가 "Cannot convert value of type CountableRange<Int> to expected argument Int".

모든 셀을 삭제하는 올바른 방법은 무엇입니까 있다고?

+1

데이터 소스 배열의 모든 항목 ('removeAll()')을 삭제하고 적절한 섹션을 통과하는 tableView에서'deleteSections()'를 호출하십시오. – vadian

답변

2

코드를 보면 배열의 데이터로 tableView가 채워집니다.

그렇다면 섹션 헤더의 클릭과 해당 헤더를 탭할 수 있습니다.

array.removeAll() 

을 그리고 실행시 : 그럼 당신은 전화

tableView.reloadData() 

을 그리고 당신과 섹션 헤더에 탭을 감지 할 수 있습니다 :

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { /*to acces the section indexPath.section*/ } 

은 모든 세포가 있기 때문에 삭제 tableView를 채울 데이터가 없습니다.

관련 문제