2014-03-04 1 views
0

셀 만들기 :IOS 테이블보기 : 표보기 사용자 정의 셀 그것은 스크롤하는 동안 다른 셀의 값을 미리 채 웁니다

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

    AddEventsCell *cell= 
     [tableView dequeueReusableCellWithIdentifier:@"addevents"]; 
    NSLog(@"cell %@",cell); 
    if(cell==nil){ 
     [tableView registerNib:[UINib nibWithNibName:@"addevents" 
               bundle:nil] 
     forCellReuseIdentifier:@"addevents"]; 
     cell=[tableView dequeueReusableCellWithIdentifier:@"addevents"]; 


    } 
    cell.tag=indexPath.row; 
    return cell; 
} 

디스플레이 셀 :

-(void) tableView:(UITableView *)tableView 
    willDisplayCell:(AddEventsCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSLog(@"index path %d == %d",indexPath.row,cell.tag); 
    if(cell.tag==0){ 

     [email protected]"Event Name"; 
     [email protected]"0"; 
     [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==1){ 
     [email protected]"Category"; 
     [email protected]"1"; 
     [self.textfieldArray addObject:cell.textFieldValue]; 
    }else if(cell.tag==2){ 
     [email protected]"Upload Image"; 
     [email protected]"2"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==3){ 
     [email protected]"Time"; 
     [email protected]"3"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==4){ 
     [email protected]"Location"; 
     [email protected]"4"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==5){ 
     [email protected]"Description"; 
     [email protected]"5"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==6){ 
     [email protected]"Factilitator"; 
     [email protected]"6"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==7){ 
     [email protected]"Price"; 
     [email protected]"7"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==8){ 
     [email protected]"Notes"; 
     [email protected]"8"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==9){ 
     [email protected]"Duration"; 
     [email protected]"9"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==10){ 
     [email protected]"Program"; 
     cell.textFi[email protected]"10"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==11){ 
     [email protected]"pre-requiment"; 
     [email protected]"11"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==12){ 
     [email protected]"Target"; 
     [email protected]"12"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==13){ 
     [email protected]"Contact"; 
     [email protected]"13"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 

    }else if(cell.tag==14){ 
     [email protected]"Website"; 
     [email protected]"14"; 
      [self.textfieldArray addObject:cell.textFieldValue]; 
    } 


} 

모든 세포 개체를 추가됨 self.textfieldArray

첫 번째 bo x는 7 번째 상자에 같은 값을 표시한다는 의미입니다.

데이터의 미리 채우기를 중지합니다.

+0

'labelFieldValue'에 대해'NSArray '를 만들 수 있으며 ** cell.lableFiledValue.text = [yourArray objectAtIndex : indexPath.row]; ** –

답변

2

AddEventsCell에서 prepareForReuse을 구현 :

-(void)prepareForReuse { 
    self.lableFiledValue.text = nil; 
    self.textFieldValue.placeholder = nil; 
} 

또 다른 한가지 - willDisplayCell 통화량있는 tableView 셀 표시하는 것입니다 때마다 - 때 사용자가 스크롤있는 tableView 앞뒤로 동일한 셀에 대해 여러 번을 의미한다. textfieldArray에 bojects를 추가하는 다른 방법을 찾고 싶을 수도 있습니다. NSMutableArraysetObject:atIndexedSubscript:을 사용하거나 추가하기 전에 지정된 객체가 배열에 이미 존재하는지 확인하여이를 수행 할 수 있습니다.

+0

으로 입력 할 때이 코드를 입력하면'cellForRowAtIndexPath'에서 사용할 수 있습니다. 입력 된 값을 스크롤 한 후 텍스트 파일의 일부 값이 사라졌습니다. –

+0

필요한 경우 - 화면 밖으로 셀을 스크롤 할 때마다 다른 인덱스의 다른 셀을 표시하는 데 사용됩니다. 셀에서 변경된 것을 포함하여 인덱스 관련 모든 셀 정보를 다시 그려야합니다. 'UITextFieldDelegate' 메소드를 사용하여 textField 텍스트를 텍스트 배열에 저장하고'willDisplayCell'에 배열의 텍스트를 다시 넣을 수 있습니다. 더 읽기 : [AppleDocs] (https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier :). –

관련 문제