2013-10-01 2 views
0

응용 프로그램 내에서 코드로 폼을 만들었지 만 위아래로 스크롤하면 보이지 않는 셀이 다른 셀의 설정으로 오버라이드됩니다. 그런 경험이 있었나요? 나는 약간의 설정을 놓치고 있지만 어떤 것이 있는지 모른다.테이블 뷰의 보이지 않는 셀이 오버라이드 됨

여기 내 코드입니다. 코드가 많습니다. 죄송합니다.

static NSString *CellIdentifier = @"anmeldenCell"; 

또는 그들을 위해 리셋 기능을 준비 :하지만 난 정말 셀에 대한

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section == 0) { 
     return 4; 
    } else if (section == 1) { 
     return 4; 
    } else { 
     return 5; 
    } 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

    return 3; 
} 

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if (section == 0) { 
     return @"Perönliche Informationen"; 
    } else if (section == 1) { 
     return @"Anschrift"; 
    } else { 
     return @"myClassico Profil"; 
    } 

} 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if ([indexPath section] == 0) { 
     if ([indexPath row] == 3) { 
      return 210; 
     } else { 
      return 44; 
     } 
    } 


    else if ([indexPath section] == 1) { 
     if ([indexPath row] == 0) { 
      return 80; 
     } else if ([indexPath row] == 3) { 
      return 210; 
     } else { 
      return 44; 
     } 
    } 


    else if ([indexPath section] == 2) { 
     return 44; 
    } 


    else { 
     return 44; 
    } 

} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"anmeldenCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    if ([indexPath section] == 0) { 
     if ([indexPath row] == 0) { 
      UISegmentedControl *gender = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Frau", @"Herr", nil]]; 
      gender.frame = CGRectMake(99, 8, 124, 28); 
      gender.selectedSegmentIndex = 0; 

      [cell.contentView addSubview:gender]; 


     } else if ([indexPath row] == 1) { 
      UITextField *vorname = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 300, 44)]; 
      vorname.placeholder = @"Vorname"; 

      [cell.contentView addSubview:vorname]; 
     } else if ([indexPath row] == 2) { 
      UITextField *nachname = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 300, 44)]; 
      nachname.placeholder = @"Nachname"; 

      [cell.contentView addSubview:nachname]; 
     } else { 

      //Code below is backup code in case someone really dislikes the UIDatePicker. Code is fully functional. 
      /* 
      UITextField *gebTag = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 80, 44)]; 
      UITextField *gebMonat = [[UITextField alloc] initWithFrame:CGRectMake(108, 0, 100, 44)]; 
      UITextField *gebJahr = [[UITextField alloc] initWithFrame:CGRectMake(216, 0, 100, 44)]; 

      gebTag.placeholder = @"TT"; 
      gebMonat.placeholder = @"MM"; 
      gebJahr.placeholder = @"JJ"; 

      [cell.contentView addSubview:gebTag]; 
      [cell.contentView addSubview:gebMonat]; 
      [cell.contentView addSubview:gebJahr];*/ 

      UILabel *gebLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 280, 50)]; 
      gebLabel.text = @"Geburtsdatum"; 

      UIDatePicker *gender = [[UIDatePicker alloc] initWithFrame:CGRectMake(20, 30, 320, 180)]; 


      [cell.contentView addSubview:gender]; 
      [cell.contentView addSubview:gebLabel]; 
     } //ENDE SECTION 1 (INFORMATIONEN ZUR PERSON) 

    } else if ([indexPath section] == 1) { 
     if ([indexPath row] == 0) { 
      UITextField *adresseStrasse = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      adresseStrasse.placeholder = @"Straße"; 

      UITextField *adresseHNR = [[UITextField alloc] initWithFrame:CGRectMake(180, 30, 120, 44)]; 
      adresseHNR.textAlignment = 2; 
      adresseHNR.placeholder = @"Hausnummer"; 

      [cell.contentView addSubview:adresseStrasse]; 
      [cell.contentView addSubview:adresseHNR]; 
     } else if ([indexPath row] == 1) { 
      UITextField *adresseZusatz = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      adresseZusatz.placeholder = @"Adresszusatz (optional)"; 

      [cell.contentView addSubview:adresseZusatz]; 
     } else if ([indexPath row] == 2) { 
      UITextField *adressePLZ = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 100, 44)]; 
      adressePLZ.placeholder = @"PLZ"; 

      UITextField *adresseOrt = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, 170, 44)]; 
      adresseOrt.placeholder = @"Ort"; 

      [cell.contentView addSubview:adressePLZ]; 
      [cell.contentView addSubview:adresseOrt]; 
     } else { 

      UILabel *land = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 150, 20)]; 
      land.text = @"Land"; 

      länderPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 300, 180)]; 
      [länderPicker setDelegate:self]; 
      array = [[NSMutableArray alloc] init]; 
      [array addObject:@"Deutschland"]; 
      [array addObject:@"Österreich"]; 
      [array addObject:@"Schweiz"]; 

      [cell.contentView addSubview:land]; 
      [cell.contentView addSubview:länderPicker]; 

     } //ENDE SECTION 2 (ADRESSEN INFORMATIONEN) 
    } else if ([indexPath section] == 2){ 
     if ([indexPath row] == 0) { 
      UITextField *email = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      email.placeholder = @"E-Mail"; 

      [cell.contentView addSubview:email]; 
     } else if ([indexPath row] == 1) { 
      UITextField *telefon = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      telefon.placeholder = @"Telefon"; 

      [cell.contentView addSubview:telefon]; 
     } else if ([indexPath row] == 2) { 
      UITextField *mtelefon = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      mtelefon.placeholder = @"Mobiltelefon (optional)"; 

      [cell.contentView addSubview:mtelefon]; 
     } else if (indexPath.row == 3) { 
      UITextField *passwort = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      passwort.placeholder = @"Passwort"; 

      [cell.contentView addSubview:passwort]; 
     } else { 
      UITextField *passwortWiederholung = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 280, 44)]; 
      passwortWiederholung.placeholder = @"Passwort wiederholen"; 

      [cell.contentView addSubview:passwortWiederholung]; 
     } //ENDE SECTION 3 (MYCLASSICO ACCOUNT INFORMATIONEN) 
    } 


    return cell; 
} 


-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 
    return [array count]; 
} 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { 

    return 1; 
} 

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    return [array objectAtIndex:row]; 
} 

답변

0

를 사용하여 다른 식별자를 어디서부터 시작 모른다.

문제는 섹션간에 셀을 다시 사용한다는 것입니다. 여기에 하위 뷰를 추가하고 있습니다 [cell.contentView addSubview : gender]; 그리고 당신은 결코 그것을 제거하지 않을 것입니다 - 그래서 그것은 동일한 셀에 여러 번 추가 될 것입니다 +이 뷰를 가진 셀은 다른 섹션에서도 사용될 것입니다.

섹션 별 맞춤 셀을 준비하고 다른 셀 식별자를 사용하는 것이 가장 좋습니다. 또한 그것들을 재사용 할 때 서브 뷰를 여러 번 추가하는 대신 적절히 뷰를 얻는 것이 좋습니다.

BTW. 섹션에 대한 열거 형을 사용하여 1,2,3,4 대신 kSectionMyProfile 등을 사용합니다.

+0

dequeReusableCellWithIdentifier에 의해 처리되지 않아야합니까? –

+0

그것으로 처리됩니다 -하지만 당신이 다른 세포를 동일한 식별자로 사용한다면 다른 모든 세포를 취급합니다 - 이전에 사용 된 세포를 얻지 못합니다. 생각해보십시오. 셀에 하위 뷰를 추가하면 결코 제거 할 수 없습니다. 대기열에서 제외하면 동일한 셀이 다시 반환되며 해당 하위 뷰를 해당 함수를 통과 할 때마다 다시 추가합니다. –

+0

그래, 알았어. 지금 수정하는 방법을 확인해야합니다 ... –

관련 문제