我搜索和搜索這個問題,我承認我可能會錯過一些東西,但我沒有想法。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,但我不知道它是什麼。