Correct use of alertController with input box

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")];

            return ;

        }else{

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

 

        }

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

 

    }]];

    

    //Add a cancel button

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

    

    //present出AlertView

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

 

Pay attention to the red background, not writing like this will cause the page not to be released**************************

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325015644&siteId=291194637