플레이어 6에서 플레이어 6까지 6 행이있는 테이블 뷰가 있습니다. 사용자는 플레이어 이름을 입력하고 스 와이프하고 '삭제'를 눌러 행을 삭제할 수 있습니다. 행의 텍스트 필드에 텍스트가있을 때 문제가 발생합니다. 예를 들어 처음 3 행의 텍스트 필드에 'One'을 'Three'로 채 웁니다. '3'이라는 행 3을 삭제하면 행이 삭제되지만 텍스트 필드의 'Three'텍스트는 플레이어 4의 행 아래로 이동합니다. 이 문제를 해결하는 가장 좋은 방법은 무엇입니까?UITableView에서 행을 삭제할 때 UITextField 내용을 삭제합니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"playerCell";
playerCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
cell.playerLabel.text = [[_playerNames objectAtIndex:indexPath.row]objectForKey:@"title"];
NSString *test = [NSString stringWithFormat:@"%@", cell.playerNameBox.text];
cell.playerNameBox.tag = indexPath.row;
NSString *key = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
[[NSUserDefaults standardUserDefaults]
setObject:test forKey:key];
return cell;
}
행 삭제 : 섹션의 행
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[_playerNames removeObjectAtIndex:indexPath.row];
[Table reloadData];
}
}
수 = 당신의 "cellForRowAtIndexPath
"방법에서 6
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _playerNames.count;
}
셀에 대한 사용자 정의 클래스가 있다고 가정하면'prepareForReuse' 메소드에서 텍스트 필드를'nil'으로 설정하십시오. – bobnoble
이렇게하면 모든 텍스트 필드의 텍스트가 삭제됩니다. 해당 행의 텍스트 필드에서 텍스트를 삭제하는 방법이 있습니까? –