2013-02-04 4 views
1

UITableView에서 스크롤 할 때 셀 텍스트 필드 값에 문제가 있습니다. 아래로 스크롤하여 사용자 정의 셀을 숨기면 textField의 값이 삭제됩니다. dequeueReusableCellWithIdentifier 메소드가 작동하지 않습니다. 나는이있다 : 일반적으로 reuseIdentifier 당신이 펜촉에서보기를로드하기 때문에 사용하지 않는있는 UITableViewCell의 initWithStyle:reuseIdentifier: 방법에 할당iPhone dequeueReusableCellWithIdentifier with 텍스트 필드 삭제 값이있는 사용자 정의 셀

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

static NSString *SectionsTableIdentifier = @"MyCustomCell"; 

MyCustomCell *cell = (MyCustomCell *) [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier]; 

    if (cell == nil) { 
     NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil]; 
     cell = [objects objectAtIndex:0]; 
    } 

cell.labelCustomAttribute.text= @"Attribute Name"; 
cell.textFieldCustomAttribute.delegate = self; 

return cell; 


} 

답변

0

.

이 속성은 읽기 전용이므로 이후에 설정할 수 없습니다.

은 아마 당신은

이제 어떻게 귀하의 경우에 일어나는 것은 새로운 세포를 만들 수 있다는 것입니다 ... 표준 initWithStyle:reuseIdentifier:를 사용하여 셀을 instanciating 시도하고 셀의 내용 없음의 서브 뷰로 펜촉에서보기를 추가 할 수 있습니다 Table View에 표보기가 필요할 때마다 분명히, 이것은 효과가 없을 것입니다. 실제로 셀을 재사용하는 경우 텍스트 필드의 내용을 어딘가에 저장하고 (데이터 소스가 바람직 함) 셀을 다시 사용할 때 배치해야합니다. 셀을 저장하지 않으면 셀을 재사용 할 때 셀이 표시되었던 이전 행의 데이터가 포함됩니다.

+0

방법이 태그 값이 저장되어 있는지 확인? – Dab88

1

viewDidLoad 메서드에서 tableView를 사용하여 사용자 지정 셀을 등록한 다음 dequeueReusableCellWithIdentifier를 사용하는 것이 더 간편합니다. 셀을 등록 할 경우 dequeue 메소드는 자동으로 재사용 가능한 셀을 선택하거나 새 사용자 정의 셀을 할당합니다 (사용할 수있는 셀이없는 경우).

예 :

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Get a point to the customized table view cell for MyCustomCell 
    UINib *myCustomCellNib = [UINib nibWithNibName:@"MyCustomCell" bundle:nil]; 
    // Register the MyCustomCell with tableview 
    [[self tableView] registerNib:myCustomCellNib forCellReuseIdentifier:@"MyCustomCell"]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *SectionsTableIdentifier = @"MyCustomCell"; 
    MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier]; 

    cell.labelCustomAttribute.text= @"Attribute Name"; 
    cell.textFieldCustomAttribute.delegate = self; 

    return cell; 

} 
관련 문제