Reputation: 1208
I am developing an app where I have a UITableView with custom cells. Custom cells contain textfield and buttons.
Requirement: The textfield/buttons should be disabled when the table is in edit mode (The user should only be able to delete cells and not interact with the contents. The user should exit edit mode and then interact with the textfields/buttons). You can also refer "Reminders" app in iPad, the content cannot be edited in edit mode.
Problem: The user is still able to click on textfield (keyboard is made visible), when the table is in Edit mode.
What I have done: If user clicks any button I do nothing in my button's action method if the table is in Edit mode which is fine fro Buttons.
if ([tableView isEditing]) {
return;
}
The issue is for textfields, I am not able to remove interaction of the textfield when in Edit mode. cellForRow is not getting called when table enters into Edit mode so that I can disable the interaction.
Is there a way where I can disable the interaction while entering into Edit Mode and enable upon exit of Edit mode.
Thank you in advance. Any pointers would be appreciated.Please let me know if you require more information about the issue
Upvotes: 0
Views: 1891
Reputation: 5064
Use following code to disable editing if textFields in table view
[yourTextField endEditing:YES];
Upvotes: 0
Reputation: 25692
1) Resign any edit text Field first
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
for (UITableViewCell *cell in [tableView visibleCells]) {
for (UIView *aView in cell.contentView.subviews) {
if ([aView isKindOfClass:[UITextField class]]) {
[aView resignFirstResponder];
break;
}
}
}
}
2) Then Dont allow any textfield to edit
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if ([tableView isEditing]) {
return NO;
} else {
return YES;
}
}
Upvotes: 0
Reputation: 2225
You can use below delegate method of UITextField for the same:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if ([tableView isEditing]) {
return NO;
} else {
return YES;
}
}
Upvotes: 3