I have created a custom cell, containing a text field. I would like the keyboard to disappear when the user presses the done button (as seen in the screen shot below).
The custom cell is located in "AccountViewCell". In my code, I call and display this custom cell:
- (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
static NSString *CellIdentifier = @"AccessCard";
static NSString *Cellnib = @"AccountViewCell";
AccountViewCell *cell = [tableView2 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:Cellnib owner:self options:nil];
cell = (AccountViewCell *)[nib objectAtIndex:3];
}
cell.data.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
if (indexPath.section == 1)
{
static NSString *CellIdentifier = @"Password";
static NSString *Cellnib = @"AccountViewCell";
AccountViewCell *cell = [tableView2 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:Cellnib owner:self options:nil];
cell = (AccountViewCell *)[nib objectAtIndex:4];
}
cell.data.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
return 0;
}
The user is able to input text, however I cannot seem to make the keyboard disappear.
I have also created a method in AccountViewCell to hide the keyboard:
- (void)textfieldInput
{
UIToolbar* padToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
padToolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self
action:@selector(doneWithPad)];
[doneButton setWidth:65.0f];
padToolBar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
doneButton,
nil];
[padToolBar sizeToFit];
textField.inputAccessoryView = padToolBar;
}
But when I call it in the cellForRowAtIndexPath, it does not work.
AccountViewCell* keyboard = [[AccountViewCell alloc] init];
[keyboard textfieldInput];
I am wondering if there is a way to hide the keyboard when the done key is pressed. A screen shot of my application is below: