带输入框alertController的正确使用

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:Localkey(@"Add the nickname") message:Localkey(@"Add the sensor's nickname") preferredStyle:UIAlertControllerStyleAlert];

    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        

        textField.placeholder = Localkey(@"nickname");

    }];

      __weak typeof(self)weakSelf = self;

      __weak typeof(alertController)weakAlert = alertController;

    [alertController addAction:[UIAlertAction actionWithTitle:Localkey(@"Confirm") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        UITextField *textField = weakAlert.textFields.firstObject;

        if (textField.text.length < 1) {

            [MBProgressHUD showError:Localkey(@"Nickname is empty, add failure")];

扫描二维码关注公众号,回复: 85212 查看本文章

            return ;

        }else{

            [[TcpSocketManger manager] sendCmd:0xa1 withDeviceID:weakSelf.deviceId andData:[PacketFactory change28BytesDataOfString:textField.text]];

        }

        NSLog(@"%@",textField.text);

    }]];

    

    //添加一个取消按钮

    [alertController addAction:[UIAlertAction actionWithTitle:Localkey(@"Cancel") style:UIAlertActionStyleCancel handler:nil]];

    

    //present出AlertView

    [self presentViewController:alertController animated:true completion:nil];

注意红色背景,不这样写会造成页面不释放**************************

猜你喜欢

转载自www.cnblogs.com/fendoulushangdefenqing/p/8967150.html