【发布时间】:2015-06-07 15:08:30
【问题描述】:
我制作了一个包含 UITextField 和 UITableView 的应用程序。 如果用户在 UITextField 中输入一些文本,我想禁用 UITableView 的所有功能/按钮。因此,如果用户使用 UITextField,则无法在 UITableViewCell 上向左滑动(通常会出现删除按钮)。因此,用户只能在显示键盘时使用 UITextFiled。
我该怎么做?
【问题讨论】:
我制作了一个包含 UITextField 和 UITableView 的应用程序。 如果用户在 UITextField 中输入一些文本,我想禁用 UITableView 的所有功能/按钮。因此,如果用户使用 UITextField,则无法在 UITableViewCell 上向左滑动(通常会出现删除按钮)。因此,用户只能在显示键盘时使用 UITextFiled。
我该怎么做?
【问题讨论】:
使用文本字段委托方法
- (void)textFieldDidBeginEditing:(UITextField *)textField{
//check if(textfield==yourtextfield) if you have more than one textfields
tableView.userInteractionEnabled = NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
tableView.userInteractionEnabled = YES;
}
【讨论】:
您可以在 NSNotificationCenter 中调用 keyboardWillShow(和 WillHide)通知时禁用按钮。
只需在从KeyboardWillHide 和NO 调用的选择器中调用YES
- (void)keyboardWillShow:(NSNotification *)notification {
//disable button here
}
【讨论】:
在你的 UITextField 的委托方法中试试这个:
- (BOOL) textField: (UITextField *)theTextField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string
{
if (theTextField == yourTextField){
yourButtonOutlet.userInteractionEnabled = NO;
}
}
【讨论】: