है सक्षम आप अपने textFields
केवल पढ़ने के लिए संपत्ति के द्वारा चेतावनी नियंत्रक से सभी जोड़ा textfields मिलता है, आप इसे उपयोग कर सकते हैं अपने पाठ मिलता है। तरह
स्विफ्ट 3:
let alertController = UIAlertController(title: "", message: "", preferredStyle: .alert)
alertController.addTextField(configurationHandler: {(_ textField: UITextField) -> Void in
textField.placeholder = "Current password"
textField.isSecureTextEntry = true
})
let confirmAction = UIAlertAction(title: "OK", style: .default, handler: {(_ action: UIAlertAction) -> Void in
print("Current password \(String(describing: alertController.textFields?[0].text))")
//compare the current password and do action here
})
alertController.addAction(confirmAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {(_ action: UIAlertAction) -> Void in
print("Canelled")
})
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: { _ in })
नोट: alertController.textFields [0] .text वैकल्पिक है,
ऑब्जेक्टिव-सी उपयोग करने से पहले यह खोलने:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Current password";
textField.secureTextEntry = YES;
}];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Current password %@", [[alertController textFields][0] text]);
//compare the current password and do action here
}];
[alertController addAction:confirmAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Canelled");
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
तकइस लाइन में, यह पहले टेक्स्टफील्ड को एलर कंट्रोलर में जोड़ा जाएगा और इसका टेक्स्ट प्राप्त होगा।
https://github.com/KiritVaghela/UIAlertController –