나는 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;
}
또한 tableviewcell은 소비자가 백엔드에서 설정 한 내용으로 채워지므로 물론 역동적입니다. – TheChef
매우 혼란 스럽습니다. 셀이 있고 인덱스 경로를 알고 싶다면'indexPathForCell'을 사용하십시오. 그러나 배열 인덱스가 있고 인덱스 경로와 연관시키고 싶습니다. 이것은 dataSource 객체의 책임입니다. –
예, 이해했습니다 ... 이와 비슷한 것을 사용하려고했습니다. NSIndexPath * newIndex = [NSIndexPath indexPathForRow : 0 inSection : 0]; DBSectionDetailsTableViewCell * cell2 = (DBSectionDetailsTableViewCell *) [listTable cellForRowAtIndexPath : newIndex]; 내 "저장"기능에서 하지만 여전히 모든 "null/nil"반환했습니다. 나는 태그를 붙이는 길을가는 것이 더 나을 것이라고 생각한다. NSIndex를 사용하여 모든 태그와 추가 함수 호출을 수행하지 않고도 원하는 것을 얻을 수 있는지 알고 싶다. – TheChef