-1

나는 5 개의 다른 세포를 가진 tableviewcell가있다. 각보기에는 다음 중 하나의 레이블이 있습니다. 1 텍스트 필드, 1 텍스트,보기 1, 스위치 또는 1 슬라이더. 사용자가 입력 한 정보를 검색 할 수 있도록 색인 경로에서 행에 대한 tableviewcell을 찾으려고합니다. 다음은 셀과 다른 스위치에 대한 코드입니다. 가능한 경우이를 달성하는 방법을 알아야합니다. 감사합니다. (p.s) 행에 셀을 찾는 대신 요소에 태그를 지정하는 것이므로 태그 코드가 표시됩니다.배열에서 채워지는 tableviewcell의 색인 경로를 가져 오는 방법은 무엇입니까?

-(UITableViewCell *)listCell:(UITableView *)tableView IndexPath:(NSIndexPath*)indexPath 
{ 
static NSString *textFieldIdentifier = @"textFieldCell"; 
static NSString *textViewIdentifier = @"textViewCell"; 
static NSString *switchIdentifier = @"switchCell"; 
static NSString *seekBarIdentifier = @"seekBarCell"; 
static NSString *datePickerIdentifier = @"datePickerCell"; 

//DBSectionDetailsTableViewCell *cell = (DBSectionDetailsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:textViewIdentifier]; 
UITableViewCell *cell6 = [tableView dequeueReusableCellWithIdentifier:datePickerIdentifier]; 


results = [listArray objectAtIndex:[indexPath row]]; 


if([indexPath row] < listArray.count) 
{ 
    if (([[results objectAtIndex:2]isEqualToString:@"EditText"])) 
    { 

     DBSectionDetailsTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:textFieldIdentifier forIndexPath:indexPath]; 
     cell2.titleLabel.text = [results objectAtIndex:1]; 
     //title button 
     cell2.textField.tag = [indexPath row]; 
     cell2.textField.delegate = self; 

     [cell2.textField addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventTouchUpInside]; 


    return cell2; 
    } 

    else if (([[results objectAtIndex:2]isEqualToString:@"EditTextLarge"])) 
    { 
     TextViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:textViewIdentifier forIndexPath:indexPath]; 

     // cell = textFieldCell; 
     cell.titleLabel.text = [results objectAtIndex:1]; 
     cell.textView.tag = [indexPath row]; 
     cell.textView.delegate = self; 
     // [cell.textView addTarget:self action:@selector(textViewDidEndEditing:) forControlEvents:UIControlEventTouchUpInside]; 


     return cell; 
    } 

    else if (([[results objectAtIndex:2]isEqualToString:@"Switch"])) 
    { 

     SwitchTableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:switchIdentifier forIndexPath:indexPath]; 


     // cell3 = switchCell; 
     cell3.titleLabel.text = [results objectAtIndex:1]; 
     cell3.switchOutlet.tag = [indexPath row]; 


     return cell3; 
    } 

    else if (([[results objectAtIndex:2]isEqualToString:@"SeekBar"])) 
    { 

     SeekBarTableViewCell *cell4 = [tableView dequeueReusableCellWithIdentifier:seekBarIdentifier forIndexPath:indexPath]; 


     //cell4 = seekBarCell; 
     cell4.titleLabel.text = [results objectAtIndex:1]; 
     cell4.slider.tag = [indexPath row]; 

     return cell4; 
    } 

    else if (([[results objectAtIndex:2]isEqualToString:@"DatePicker"])) 
    { 

     DatePickerTableViewCell *cell5 = [tableView dequeueReusableCellWithIdentifier:datePickerIdentifier forIndexPath:indexPath]; 

     //cell5 = datePickerCell; 
     cell5.titleLabel.text = [results objectAtIndex:1]; 
     cell5.datePicker.tag = [indexPath row]; 
     cell5.datePicker.delegate = self; 

     [cell5.datePicker addTarget:self action:@selector(datePickerDidEndEditing:) forControlEvents:UIControlEventTouchUpInside]; 

     return cell5; 
    } 


} 

//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 


return cell6; 

}

+0

또한 tableviewcell은 소비자가 백엔드에서 설정 한 내용으로 채워지므로 물론 역동적입니다. – TheChef

+0

매우 혼란 스럽습니다. 셀이 있고 인덱스 경로를 알고 싶다면'indexPathForCell'을 사용하십시오. 그러나 배열 인덱스가 있고 인덱스 경로와 연관시키고 싶습니다. 이것은 dataSource 객체의 책임입니다. –

+0

예, 이해했습니다 ... 이와 비슷한 것을 사용하려고했습니다. NSIndexPath * newIndex = [NSIndexPath indexPathForRow : 0 inSection : 0]; DBSectionDetailsTableViewCell * cell2 = (DBSectionDetailsTableViewCell *) [listTable cellForRowAtIndexPath : newIndex]; 내 "저장"기능에서 하지만 여전히 모든 "null/nil"반환했습니다. 나는 태그를 붙이는 길을가는 것이 더 나을 것이라고 생각한다. NSIndex를 사용하여 모든 태그와 추가 함수 호출을 수행하지 않고도 원하는 것을 얻을 수 있는지 알고 싶다. – TheChef

답변

1

당신은 [tableView cellForRowAtIndexPath:indexPath]을 사용하여 테이블에서 볼 수 세포를 가져올 수 있습니다. 화면이 꺼진 셀은 UITableView에서 제거되며 재사용 할 수있는 셀 대기열에 다시 넣을 수 있으므로 셀에 액세스 할 수 없습니다.


주 1 : 당신은 당신의 현재 데이터 상태를 저장하기 위해 UITableView에 의존해서는 안된다. 화면 밖으로 스크롤되는 셀을 버리고, 다른 곳에 데이터를 저장하지 않으면 영원히 사라집니다.


주 2 :이 코드는 특히 안전하지 않습니다 : 사용자가 각 셀을 들어갈 때 당신이 그것을 셀을 한 번에 도달 할 수 없기 때문에 당신은 정보를 저장해야

results = [listArray objectAtIndex:[indexPath row]]; 
if([indexPath row] < listArray.count) // This is always true. 
             // If it isn't true, the above 
             // objectAtIndex: will crash your app. 
+0

감사합니다. 항상 백엔드에 데이터가 있기 때문에 항상 유효합니다 ... "목록 배열"해킹 당하지 않는 한 모든 데이터가 삭제되면 잘됩니다. 전체 앱이 작동하지 않습니다. 데이터베이스를 기반으로하기 때문에 일반적입니다. 고마워요. – TheChef

+0

언제나 사실이라면 왜 그걸 전혀 확인하지 않습니까? –

+0

나는 그것을 꺼내기 시작할 수 있다고 생각하지만 처음에는이 부분에 대한 백엔드가 아직 완성되지 않았다. 따라서 삭제하는 대신 방금 전환했습니다. 프로세스를 완료 할 때 내 코드를 정리했지만이 프로세스는 아직 완료되지 않았기 때문에 줄을 주석 처리해야합니다. 그러나 다시 한 번 감사드립니다. 정보를 검색하려고하는 항목에 태그를 붙일 것입니다. 나는 그와 함께하는 추가 기능을 피하려고 애썼다. – TheChef

0

나중에 재사용 할보기에서 벗어납니다.