1. 程式人生 > >ios [self.view endEditing:YES]; [textField resignFirstResponder];隱藏鍵盤無效的問題

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;
}