我在alertview中有一个名为phoeNumberTF的文本字段。
phoneNumberTF.delegate = self;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter your phone number" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction
actionWithTitle:@"Send"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSArray * textfields = alert.textFields;
phoneNumberTF = textfields[0];
[self sendPhoneNumber:phoneNumberTF.text];
}]];
shouldChangeCharactersInRange
委托方法未被调用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
}
答案 0 :(得分:1)
phoneNumberTF不是UIalertController的一部分,因此不需要代理phoneNumberTF.delegate = self;
将configurationdelegate添加到您的UIAlertControler
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter your phone number" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.delegate = self;
}];
有关详细信息,请获取示例here