2014-05-12 4 views
1

그래서이 코드의 UITextField 텍스트 중복

if (tableView.tag == RECO_TABLE) { 
      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 
      [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
      NSString *roomName = [selectedRooms objectAtIndex:indexPath.row]; 
      [cell.cellRoomName setText:roomName]; 
     return cell; 
    } 

그리고 내 사용자 정의 셀 내부가

@property (weak, nonatomic) IBOutlet UILabel *cellRoomName; 
@property (weak, nonatomic) IBOutlet UITextField *cellRoomPrice; 

cellRoomName 괜찮 하지만 cellRoomPrice가 복제 유지하다이 내 행에 도달 할 때> 5 및 재사용 셀의 개념을 알고 있지만 시작하는 방법을 모르겠습니다.

은 BTW 여기

행 1 = 40

행 2 = 2

행 3 = 널

행 4 = null이

행 5 = null이

내 샘플 시나리오입니다

행 6 = 40

행 7 = 2

따라서 5 행마다 내 행이 복제됩니다.

+0

내가 이것에 대해 이상한 볼 수 없었다. 왜 당신은 5 행이 복제되었다고 말하고 있습니다. –

답변

1

cellRoomPrice의 값을 올바르게 설정하지 않은 것처럼 보입니다. 각 행에이 값이 이미있는 경우 각 셀/행에 대해이 값을 설정해야합니다.

사용자가 객실 가격을 편집 할 수 있으므로 해당 값을 어딘가에 저장해야합니다. 행 번호로 색인 된 배열에 저장하는 것이 좋습니다. 당신은 또한 사용자가 편집하는 행 번호를 알고 있어야합니다, 당신은 UITextFieldDelegate이 가정이 도움이 -cellForRowAtIndexPath:

희망에 태그를 설정하여 해결할 수 있습니다 -textFieldDidEndEditing:에 (값을 저장하기 위해).

+0

아이디어를 주셔서 감사합니다 ... 내 데이터 개체로 NSDictionary를 사용하고 그것을 다시 검색 NSUSerDefault에 저장 :) – RonPelayo

0

가치가 설정되지 않았으므로 행 도달 횟수가 5를 초과했습니다. 셀 이전의 TableView 재사용 때문에 새로운 값을 설정하지 않으면 tableview가 셀 앞에 사용하게됩니다!

1

셀을 할당했는지 여부를 확인하지 않았기 때문에이 방법을 사용하십시오.

if (tableView.tag == RECO_TABLE) { 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 
    if(!cell) { 
     cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"]; 
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    } 

    NSString *roomName = [selectedRooms objectAtIndex:indexPath.row]; 
    [cell.cellRoomName setText:roomName]; 

    return cell; 
} 
1

셀은 또한 다음 셀의 텍스트 필드에 입력하는 텍스트 전무인지

if (tableView.tag == RECO_TABLE) { 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 
    if(!cell) { 
     cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"]; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    NSString *roomName = [selectedRooms objectAtIndex:indexPath.row]; 
    [cell.cellRoomName setText:roomName]; 
    return cell; 
} 

그리고 당신은 수표의 첫 번째해야 할 코드에서 몇 가지 변화가 일부에 저장할 필요가 있습니다 다른 배열의 "selectedRoomsPrices"과에서 말하는 "cellForRowAtIndexPath :"이 같은 "cell.cellRoomPrice"에서뿐만 아니라 그 값을 카운트를 확인하고 설정해야합니다

if (tableView.tag == RECO_TABLE) { 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 
    if(!cell) { 
     cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"]; 
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    NSString *roomName = [selectedRooms objectAtIndex:indexPath.row]; 
    [cell.cellRoomName setText:roomName]; 
    NSString *roomPrice = @""; 
    if(selectedPrices.count > indexPath.row) { 
     roomPrice = [selectedRoomsPrices objectAtIndex:indexPath.row]; 
    } 
    [cell.cellRoomPrice setText:roomPrice]; 

    return cell; 
}