기본적으로 모든 textField에 잘못된 데이터가 표시됩니다 (모든 것이 섞여 있습니다). 나는 UITableView에서 재사용 가능한 셀의 굉장한 최적화 때문에 색인 경로가 끊임없이 변하기 때문에 이것이 문제를 해결하는 방법을 모르겠다는 것을 알고있다.iOS 6 UITableViewCell 안의 UITableViewCell 섹션이 스크롤 할 때 잘못된 데이터를받습니다.
동일한 셀에 UILabel이있는 경우 모든 레이블보기에 특정 태그를 추가하여이 문제를 해결 했으므로 tableview는 어떤 데이터가 뷰에서 반환 될지를 알고 있지만 어떤 이유로이 텍스트 필드보기에는 불가능합니다 . 어떤 도움에 감사드립니다
#define DESCRIPTION_TAG 10
#define TEXTFIELD_TAG 11
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Description Cell";
// Intatiating my own TableViewCell
CustomLocationCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell){
cell = [[CustomLocationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.rowText = (UILabel *) [cell viewWithTag:DESCRIPTION_TAG]; // returning view with unique tag
cell.rowTextField = (UITextField *)[cell viewWithTag:TEXTFIELD_TAG]; // NOT WORKING!!! Data get mix up
cell.rowTextField.delegate = cell; // sending the delegate to custom class cell
cell.delegate = self; // make connection with my @protocol
switch (indexPath.section) {
case 0:
cell.rowText.text = [self.descriptions objectAtIndex:indexPath.row];
cell.rowTextField.placeholder = [self.descriptionsPlaceholder objectAtIndex:indexPath.row];
break;
case 1:
cell.rowText.text = [self.rooms objectAtIndex:indexPath.row];
cell.rowTextField.placeholder = [self.contentPlaceholder objectAtIndex:indexPath.row];
break;
default:
break;
}
return cell;
}
:
여기 내 코드입니다. 여기
는 내 데이터 소스의 업데이트입니다 : 내 UILabel의 아웃렛을해야합니까 내 CustomTableViewCell에 과의 UITextField// UITableView DataSource
- (NSArray *)sections
{
if (!_sections){
_sections = [[NSArray alloc] initWithObjects:@"First Description", @"Second Descriptions", nil];
}
return _sections;
}
- (NSMutableArray *)rooms
{
if (!_rooms){
_rooms = [[NSMutableArray alloc] init];
}
return _rooms;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.sections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
return [self.descriptions count];
break;
case 1:
return [self.rooms count];
break;
default:
break;
}
return 0;
}
표시되는 텍스트를 변경하지 마십시오. –
[cell.contentView viewWithTag : TEXTFIELD_TAG]을 (를) 사용해 볼 수 있습니까? – Anupdas
응답 해 주셔서 감사합니다! @ A-Live, 사용자가 텍스트를 쓰고 테이블을 스크롤 할 때이 새로운 텍스트가 섞여서 문제가되지 않는다고 생각합니다. – Pompeyo