2013-07-04 4 views
0

У меня есть раскадровка, внутри которой я вставил полосу прокрутки, так как контент для отображения слишком много, чтобы отображаться сразу. полоса прокрутки включает в себя:UIScrollbar не прокручивается, когда появляется клавиатура

  • показан вид изображения
  • метка
  • сгруппированной таблицы вид

Строки представления таблицы бывают двух видов. Первый вид (определенный контроллером regularRegistrationCellVC) содержит текстовое поле и метку. Когда я нажимаю в любом текстовом поле в любой сгенерированной ячейке, появляется клавиатура и текстовое поле становится скрытым. кроме того, невозможно прокрутить содержимое представления вверх, чтобы увидеть, что находится под клавиатурой. так, следуя директивам Apple, я добавил этот код в контроллер, содержащий полосу прокрутки:

регистрирующий уведомления

- (void)registerForKeyboardNotifications 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWasShown:) 
               name:UIKeyboardDidShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillBeHidden:) 
               name:UIKeyboardWillHideNotification object:nil]; 
} 

клавиатуры Called когда UIKeyboardDidShowNotification отправляется

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0); 
    scrollPanel.contentInset = contentInsets; 
    scrollPanel.scrollIndicatorInsets = contentInsets; 

    // If active text field is hidden by keyboard, scroll it so it's visible 
    // Your application might not need or want this behavior. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= kbSize.height; 
    if (!CGRectContainsPoint(aRect, activeField.frame.origin)) { 
     CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height); 
     [scrollPanel setContentOffset:scrollPoint animated:YES]; 
    } 
} 

Вызывается, когда клавиатура исчезает

- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
{ 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scrollPanel.contentInset = contentInsets; 
    scrollPanel.scrollIndicatorInsets = contentInsets; 
} 

управления событием начала редактирования

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    activeField = textField; 
    NSLog(@"inizio digitazione\n"); 
} 

управление в случае прекращения редактирования

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    activeField = nil; 
} 

где activeField является глобальной переменной моего контроллера ,

Затем я изменил часть кода, создавая первый вид клетки, таким образом, что каждая новая клетка первого рода имеет свой контроллер представления в качестве делегата:

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

    if (indexPath.section == 0) { 
     static NSString *CellIdentifier = @"regularRegistrationCell"; 

     regularRegistrationCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[regularRegistrationCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 

     cell.regularFieldName.text = [self.orientationItems objectAtIndex:indexPath.row]; 
     cell.regularTextField.delegate = self; 
     return cell; 

    } 

    else{ 
     static NSString *CellIdentifier = @"orientationRegistrationCell"; 

     orientationRegistrationCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[orientationRegistrationCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     } 

     cell.fieldLabel.text = [self.orientationItems objectAtIndex:[orientationItems count]-1]; 

     NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; 
     NSString *val = nil; 

     if (standardUserDefaults) 
      val = [standardUserDefaults objectForKey:@"orientation"]; 

     if (val == nil) 
      cell.orientationLabel.text = @"Eterosessuale"; 

     else 
      cell.orientationLabel.text = val; 

     return cell; 

    } 
} 

Наконец, я заявил, что мой (содержащий полосу прокрутки и ее содержимое) реализует UITextFieldDelegate. Используя распечатки NSLog, я понял, что каждый раз, когда нажимается текстовое поле, функция управления событием обязательно выполняется.

Не могли бы вы сказать, где я ошибаюсь?

спасибо за помощь

ответ

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