다른 클래스에서 생성 한 0bject를 표시하는 tableView가 있습니다. 객체는 Array에 저장됩니다.commitEditingStyle을 사용하여 행 및 섹션 삭제
whiskyArray에서 데이터를 tableView로 옮기는 사전을 만듭니다. 사전 먼저 키와 문자와 값으로 객체의 이름으로 구성됩니다 이제
var alphabetizedWhiskies = [String: [WhiskyBuilder]]()
나는 다음과 같은 방법으로 수행있는 tableView,에서 commitEditingStyle:
와 세포를 삭제하려면 :
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
if editingStyle == UITableViewCellEditingStyle.Delete {
alphabetizedWhiskies[Array(alphabetizedWhiskies.keys.sort())[indexPath.section]]!.removeAtIndex(indexPath.row)
if alphabetizedWhiskies[Array(alphabetizedWhiskies.keys.sort())[indexPath.section]]!.count == 0 {
alphabetizedWhiskies.removeValueForKey(Array(alphabetizedWhiskies.keys.sort())[indexPath.section])
tableView.deleteSections(NSIndexSet(index:indexPath.section), withRowAnimation: .Fade)
}else {
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
alphabetizedWhiskies.removeValueForKey(Array(alphabetizedWhiskies.keys.sort())[indexPath.row])
}
}
이 방법은 실제로 완벽하게 작동하며 셀은 삭제됩니다. 그러나이보기로 돌아올 때마다 삭제 된 셀이 테이블에 다시 나타납니다. 저는 신속한 새로운 기능입니다. 그러나 셀이 사전에서 삭제되었지만 whiskyArray의 개체는 삭제되지 않았기 때문에 이러한 현상이 발생한다고 생각합니다. 나는 whiskyArray에서 개체를 삭제하려고했습니다 :
whiskyArray.removeAtIndex(indexPath.row)
그러나이와
은 whiskyArray에있는 모든 개체는 내가 삭제하고 싶은 삭제 된 것이 아니라. 그렇다면 어떻게 tableView에서 셀을 삭제하여 whiskyArray에서 삭제할 올바른 객체에 액세스 할 수 있습니까? tableViewCells를 삭제하는 방법에 대해 많이 알았지 만 배열에서 의미 객체를 삭제하는 방법을 찾지 못했습니다. 아무도 나를 도울 수 있습니까?