선택한 행을 배열에 추가하고 해당 행을 선택 해제 할 때 배열에서 제거하는 함수를 만들려고합니다. 너희들이 나를 도와 줄 수있어?didSelectRow에 추가하고 신속하게 3.0에서 didDeselectRow를 제거하는 방법
행 선택 기능 :
var exercises = [exercise]() // Array that will be filled by selected rows
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedCell = tableView.cellForRow(at: indexPath) as? exerciseCell
let exercisesSelected = selectedCell?.exerciseNameLbl.text
exercisenames.insert(exercisesSelected!, at: 0)
}
이 내 선택 해제 위임 방법입니다 :
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let selectedCell = tableView.cellForRow(at: indexPath) as? exerciseCell
if exercisenames.count < 1 {
print("empty array")
}else{
exercisenames.remove(at: indexPath.row)
print(exercisenames)
}
}
어떤 도움을 기대, 감사합니다!
케빈.
다른 대리자 메서드'deselectRowAtIndexPath이 있습니다를'. 거기에서 배열에서 제거 할 수 있습니다. –
당신이 묻고있는 것이 분명하지는 않습니다 ... 대개 데이터 배열 (셀로 나타낼 데이터)에서 객체를 추가/제거합니다. 따라서 배열을 기반으로 객체를 다른 객체로 옮기고 싶습니까? 이 경우 @ New16의 대답을 사용할 수 있지만 코드가 잘못되었습니다. – Zeb
실제로는 선택 취소시 해당 오브젝트를 제거하려고합니다. 따라서 대리인이 처리해야합니다. –