0

我搜索和搜索这个问题,我承认我可能会错过一些东西,但我没有想法。UITableView table中的UITextFieldFooterView弹出屏幕上resignFirstResponder

我有一个UITableView tableFooterView为UITextField在我mainClass:

// Set table footer 
PAPPhotoDetailsFooterView *footerView = [[PAPPhotoDetailsFooterView alloc] initWithFrame:[PAPPhotoDetailsFooterView rectForView]]; 
commentTextField = footerView.commentField; 
commentTextField.delegate = self; 
self.tableView.tableFooterView = footerView; 

文本域是在PAPPhotoDetailsFooterView类设置像这样:

commentField = [[UITextField alloc] initWithFrame:CGRectMake(25.0f, 10.0f, 227.0f, 31.0f)]; 
commentField.font = [UIFont systemFontOfSize:kCommentCellContentLabelFontSize]; 
commentField.placeholder = @"Name photo"; 
commentField.returnKeyType = UIReturnKeySend; 
commentField.autocapitalizationType = UITextAutocapitalizationTypeNone; 
commentField.autocorrectionType = UITextAutocorrectionTypeNo; 
commentField.textColor = [UIColor colorWithRed:73.0f/255.0f green:55.0f/255.0f blue:35.0f/255.0f alpha:1.0f]; 
commentField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
[commentField setValue:[UIColor colorWithRed:154.0f/255.0f green:146.0f/255.0f blue:138.0f/255.0f alpha:1.0f] forKeyPath:@"_placeholderLabel.textColor"]; 
[mainView addSubview:commentField]; 

下面是我的mainClass我textFieldShouldReturn方法:

#pragma mark - UITextFieldDelegate 
- (BOOL)textFieldShouldReturn:(UITextField *)textField { 

    // Call method to store comment 
    NSString *trimmedComment = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 
    [self parseAndStoreComment:trimmedComment]; 

    // Reset the text field 
    [textField setText:@""]; 
    return [textField resignFirstResponder]; 

} 

而我的键盘方法:

- (void)keyboardWillShow:(NSNotification*)note { 
    // Scroll the view to the comment text box 
    NSDictionary* info = [note userInfo]; 
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 
    [self.tableView setContentOffset:CGPointMake(0.0f, self.tableView.contentSize.height-kbSize.height) animated:YES]; 

} 


- (void)keyboardWillHide:(NSNotification*)note {  
    [self.tableView setContentOffset:CGPointMake(0.0f, self.tableView.tableFooterView.frame.origin.y) animated:YES]; 
} 

当我点击关闭文本框 - 或 - 当我打回键盘上发生了什么事是,那么看起来的tableView滚动到无论我在keyboardWillHide设置,但后来随即就会迅速向上滚动到tableView完全上下的位置。

我试着将setContentOffset的动画设置为在keyboardWillHide的2.0f秒,看看会发生什么,这将导致我指定的contentOffset滚动超过2秒,但是之后立即会拍摄离屏。

在我的代码滚动之后,某事物正在滚动tableView,但我不知道它是什么。

回答

0

所以我意识到这只发生在模拟器上。我一直在模拟器和设备上测试应用程序,但我想每次尝试调试此问题时,我只在模拟器上进行过测试。

不知道为什么它在模拟器上发生。