I have this UITableView with custom cells that can get only predefined values, therefore I use a UIPickerView as their inputView. All is jolly good until I edit a field and
This reads like expected behavior - the picker belongs to a particular cell, that cell gets reloaded and is not the first responder any more. I guess one had to select a specific element anyway for the picker to appear, i.e. to make it first responder.
So you either need to make it become first responder again after reloading, or update the specific cell directly.
I solved this by subclassing UITextView, overriding -(BOOL)resignFirstResponder and by adding a BOOL canResign. this variable is set before reloading the data and unset a short time after.
I put my UISearchBar in its own section in a UITableView. When firing off the search, I made sure to only refresh the sections which do not contain the search bar.
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
adding:
[yourSearchBar becomeFirstResponder];
after your:
[_tableView reloadData];
did the trick
Track which cell's keyboard is active and then get that particular cell by cellForRowAtIndexPath
and make textView firstResponder
self.tableView.reloadData()
if let indexPath = self.activeIndexPath{
if let cell = createFormTableView.cellForRow(at: indexPath) as? TextViewTableViewCell {
cell.txtViewInput.becomeFirstResponder()
}
}
customTextField.canResign = NO;
[self.tableView reloadData];
customTextField.canResign = YES;
Custom text field is derived from UITextField.
.h
@interface CustomTextField : UITextField
@property (nonatomic,assign) BOOL canResign;
@end
.m
- (BOOL)canResignFirstResponder
{
return self.canResign;
}
Make sure that your custom text field is not recreated on table view reloading.