2017-03-15 1 views
0

라이브러리를 사용하지 않고 사용자 정의 셀을 사용하여 색인 경로에서 행에 하위 행을 추가하려고합니다.didselectRowAt (Swift 3) 서브 루틴을 추가 할 수있는 방법

func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 

    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {    
     return arrayEnum.count 
    } 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     var CellTB: UITableViewCell! 

      let cell = tableView.dequeueReusableCell(withIdentifier: "enumCell", for: indexPath)as! UserFlagTableViewCell 
      cell.UserflagLabel.text = arrayEnum[indexPath.row].rawValue 
      CellTB = cell 


//   let cell1 = tableView.dequeueReusableCell(withIdentifier: "freeTextCell", for: indexPath)as! FreeTextTableViewCell 
//   cell1.sendButton.addTarget(self, action: Selector("sendUserflagEvent:"), for: .touchUpInside) 
//   CellTB = cell1 


       return CellTB 

    } 
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


     self.tableView.insertRows(at: [IndexPath(row: UserFlagType.userFlagTypes.count-1, section: 0)], with: .automatic) 



     self.tableView.beginUpdates() 
     self.tableView.endUpdates() 


    } 
: 내가 이것을 시도 같은

입니다 나타납니다있는 셀 : 나는 셀을 선택하면

는 다른 셀이 작업은 각 셀 시 반복되고,이 셀 아래에 나타납니다

내가 1 절 이 난 6 행

하는 대신 array.count에 1을 추가

답변

0

이 배열에 개체를 1 개 더 추가하십시오. 그렇지 않은 경우 데이터 원본 배열보다 많은 행을 가져 오는 중 오류가 발생합니다.

그래서 :

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
//Add a row here to your array 
self.tableView.insertRows(at: [IndexPath(row: array.count - 1, section: 0)], with: .automatic) 
self.tableView.beginUpdates() 
self.tableView.endUpdates() 
} 

작동합니다. [IndexPath (행 : CurrentIndex, 섹션 : 0)]와 방금에서합니다 (arrayEnum에 새 요소를 삽입 한 다음

tableView.beginUpdates() tableView.insertRows 올바른을하고

+0

을 반영하고 어떻게 표시 할 수 있습니다 새로운 셀 ?? 이유 : '행 6을 섹션 0에 삽입하려고 시도하지만 업데이트 후 섹션 0에 여섯 개의 행만 있습니다.' libC++ abi.dylib : NSException 유형의 캐치되지 않는 예외로 종료합니다. –

+0

IndexPath가 0에서 시작하고 사용자가 array.count, 1부터 시작. 그래서 ... array.count - 1 할 필요가. 나는 대답을 편집 할 것입니다. – Mellao

+0

열거 형 목록 (6 열거 형)을 테이블보기로 만들고 나는 새 맞춤형 셀이 나타나는 셀을 선택할 때 (단추와 텍스트를 보내는 방법)를 원한다. 나는 어떻게하는지 모르겠다. 그리고 수 없습니다 배열을 열거 할 수 있습니다 –

0

안녕 : .automatic) tableView.endUpdates (를) CurrentIndex 당신이 배열의 요소를 삽입 할 요소의 인덱스에

, 자동의 tableview에 더 나를 위해 작동하지 것

관련 문제