i am wondering how i would handle closing keyboard in UITextField, i know how to do it when i do it via Outlets, but now i am declaring my textfields in code like this:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.accessoryType = UITableViewCellAccessoryNone;
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
if([indexPath row] == 0) {
playerTextField.placeholder = @"Server Address";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
} else if([indexPath row] == 1){
playerTextField.placeholder = @"Server Port";
playerTextField.keyboardType = UIKeyboardTypeDecimalPad;
playerTextField.returnKeyType = UIReturnKeyDone;
} else {
playerTextField.placeholder = @"Password";
playerTextField.keyboardType = UIKeyboardTypeDefault;
playerTextField.returnKeyType = UIReturnKeyDone;
playerTextField.secureTextEntry = YES;
}
playerTextField.backgroundColor = [UIColor clearColor];
playerTextField.autocorrectionType = UITextAutocorrectionTypeNo;
playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
playerTextField.textAlignment = UITextAlignmentLeft;
playerTextField.tag = 0;
playerTextField.clearButtonMode = UITextFieldViewModeNever;
[playerTextField setEnabled: YES];
[cell.contentView addSubview:playerTextField];
return cell;
}
How would i manage that?
Because your textfield is inside a cell, you need to tag it, which you already are, however i would recommend using something different than
0. then whenever you need to resign it (assuming you know which cell to look for) :if you dont know which cell it is then youll need to loop through all the cells.
hope this helps