ios [self.view endEditing:YES]; [textField resignFirstResponder];隐藏键盘无效的问题

如图,我的注册功能是点击详细地址的时候,要自动跳到地址页面。但是有个问题,就是在代理方法里面- (void)textFieldDidBeginEditing:(UITextField *)textField设置

//这两个怎么设置也没用。在地址页面还是出现键盘
   [self.view endEditing:YES];
   [textField resignFirstResponder];

经过测试要在textFieldShouldBeginEditing里面设置,而且注意要return NO否则,这个代理方法会执行两次

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField == self.addressView.inputField) {
        [self.view endEditing:YES];
        [textField resignFirstResponder];
        XuanZeWangZhiController *selectAddress = [[XuanZeWangZhiController alloc] init];
        __weak typeof(self) wself = self;
        [selectAddress returentextblockWithBlock:^(NSString *province, NSString *city, NSString *district, NSString *address, CGFloat latitude, CGFloat longitude) {
            wself.province = province;
            wself.city = city;
            wself.district = district;
            wself.address = address;
            wself.latitude = latitude;
            wself.longitude = longitude;
            wself.addressView.inputField.text = [NSString stringWithFormat:@"%@%@%@%@",province,city,district,address];
        }];
        
                [self.navigationController pushViewController:selectAddress animated:YES];
        return NO;
    }
    return YES;
}

猜你喜欢

转载自blog.csdn.net/wangqiuwei07/article/details/83829021