2010-08-30 3 views
0

У меня возникла странная проблема. В представлении таблицы у меня есть 3 раздела, из которых 1-й раздел имеет только метки и текстовые поля. 2-й и 3-й разделы содержат текстовые поля и индикатор раскрытия информации на некоторых ячейках таблицы. Второй раздел имеет 10 ячеек, затем 3 содержит индикатор раскрытия информации и другие, имеющие текстовые поля.индикатор раскрытия сместился со своего положения после прокрутки в iphone

Моя проблема в том, что я прокручиваю представление вверх и вниз, скажем 3-4 раза, ячейки индикатора раскрытия сдвигаются оттуда и помещаются в любое место в этом разделе. Если я продолжу прокрутку вперед, индикатор раскрытия информации снова появится там. Если я удалю этот индикатор раскрытия и поместим только текстовые поля, все пройдет хорошо.

Я также попытался с помощью переключателя в случае cellForRowAtIndexPath (как указано в следующей ссылке), но ничего не помогает мне ... :( http://www.iphonedevsdk.com/forum/iphone-sdk-development/13370-uitableview-cells-uilabel-problem.html

Я много сделал Google, но не в состоянии найти решение для это.

Пожалуйста, помогите мне в этом ...

с уважением, В.М.

+0

могли бы вы опубликовать свой код? – rano

+0

Я думаю, что это проблема в вашем cellForRowAtIndexPath. Поэтому, пожалуйста, напишите этот код. – audience

+0

Привет Рано и Аудитория. Вы обнаружили какие-либо проблемы в коде, который я опубликовал. Я все еще пытаюсь найти решение ... :( –

ответ

0

Пожалуйста, найдите код для ссылки.

Первый раздел содержит 6 ячеек, вторая часть содержит 12 и то же самое с 3-й секцией. Во 2-й и 3-й секциях ячейка № 4,8,9 содержит индикаторы раскрытия, другие ячейки содержат только текстовые поля.

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

UITableViewCell *cell; 
NSInteger row = [indexPath row];NSLog(@"Row->%d",row); 
NSInteger section = [indexPath section];NSLog(@"section->%d",section); 
static NSString *CellIdentifier = @"Cell"; 
static NSString *BillingInfoCellIdentifier = @"BillingCell"; 
static NSString *DIBillingInfoCellIdentifier = @"DIBillingCell"; 
static NSString *BCellIdentifier = @"BCell"; 

switch (indexPath.section) { 
    case 0: 

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)]; 
    cellLabel.tag = 56; 
    cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    [cell.contentView addSubview:cellLabel]; 
    [cellLabel release]; 

     switch (indexPath.row) { 
      case 0: 
      case 1: 
      case 2: 
      case 3: 
      case 4: 
      case 5: 
       textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)]; 
       textField.clearsOnBeginEditing = NO; 
       textField.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       [textField setDelegate:self]; 
       [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
       textField.tag = 57; 
       [cell.contentView addSubview:textField];NSLog(@"in adding text fields"); 
       break; 
     } 
     break; 
    case 1: 
     cell = [tableView dequeueReusableCellWithIdentifier:BillingInfoCellIdentifier]; 
     if (cell == nil) { 

      switch (indexPath.row) { 
       case 0: 
       case 1: 
       case 2: 
       case 3: 
       case 5: 
       case 6: 
       case 7: 
       case 10: 
       case 11: 
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease]; 
        UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)]; 
        cellLabel.tag = 56; 
        cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
        [cell.contentView addSubview:cellLabel]; 
        [cellLabel release]; 
        cell.accessoryType = UITableViewCellAccessoryNone; 
        textField = [[UITextField alloc] initWithFrame: CGRectMake(105, 12, 200, 25)]; 
        textField.clearsOnBeginEditing = NO; 
        textField.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
        [textField setDelegate:self]; 
        [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
        textField.tag = 57; 
        [cell.contentView addSubview:textField];NSLog(@"in adding text fields"); 
        break; 
       case 4: 
       case 8: 
       case 9: 
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BillingInfoCellIdentifier] autorelease]; 
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
        cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)]; 
        cellLabel.tag = 56; 
        cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
        [cell.contentView addSubview:cellLabel]; 
        [cellLabel release]; 
        break; 
      } 
      break; 

     } 
     break; 
    case 2: 
     cell = [tableView dequeueReusableCellWithIdentifier:BCellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:BCellIdentifier] autorelease]; 
      UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)]; 
      cellLabel.tag = 56; 
      cellLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
      [cell.contentView addSubview:cellLabel]; 
      [cellLabel release]; 
     } 
    break; 
} 

} 
UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:56]; 
UITextField *TF = (UITextField *)[cell.contentView viewWithTag:57]; 

switch (indexPath.section) { 
    case 0: 
     switch (indexPath.row) { 
      case 0: 
       cellLabel.text = @"First Name:"; 
       TF. placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 1: 
       cellLabel.text = @"Last Name";//TF.text = @"Last Name:"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       NSLog(@"TF.placeholder 1->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]); 
       break; 
      case 2: 
       cellLabel.text = @"eMail";//TF.text = @"email Name:"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       NSLog(@"TF.placeholder 2->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]); 
       break; 
      case 3: 
       cellLabel.text = @"Password";//TF.text = @"pass Name:"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       NSLog(@"TF.placeholder 3->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]); 
       break; 
      case 4: 
       cellLabel.text = @"Confirm";//TF.text = @"conform Name:"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       NSLog(@"TF.placeholder 4->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]); 
       break; 
      case 5: 
       cellLabel.text = @"Phone";//TF.text = @"phone Name:"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       NSLog(@"TF.placeholder 5->%@",[[tempArray objectAtIndex:section] objectAtIndex:row]); 
       break; 
     } 
     break; 
    case 1: 
     switch(indexPath.row) { 
      case 0: 
       cellLabel.text = @"First Name"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 1: 
       cellLabel.text = @"Last Name"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 2: 
       cellLabel.text = @"Phone"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 3: 
       cellLabel.text = @"Company"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 5: 
       cellLabel.text = @"Address 1"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 6: 
       cellLabel.text = @"Address 2"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 7: 
       cellLabel.text = @"City"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 10: 
       cellLabel.text = @"Suit"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      case 11: 
       cellLabel.text = @"Zip"; 
       TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
      default: 
       cellLabel.text = @"2 else "; 
       //TF.placeholder = [[tempArray objectAtIndex:section] objectAtIndex:row]; 
       break; 
     } 
     break; 
    case 2: 
     switch (indexPath.row) { 
      case 0: 
       cellLabel.text = @"Label 2"; 
       break; 
      case 1: 
       cellLabel.text = @"Label 2"; 
       break; 
      default: 
       cellLabel.text = @"3. else Label "; 
       break; 
     } 
     break; 
    default: 
     break; 
} 
return cell; 

}

+0

Любое тело обнаружило любую ошибку в вышеуказанном коде «Я не могу решить эту проблему .. :( –

0

Попытка сделать все инициализации после выделения ячейки, без кондиционирования, если она была равна нулю раньше.

Значение:

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

Теперь остальные инициализации ячейки (это суб вид и больше)

Смежные вопросы