Chcę dodać tekst wpisu w widoku alertów ios 8. Wiem, że zostało zrobione przy użyciu UIAlertController
, ale nie mam pojęcia. Jak to zrobić?Jak dodać wpis tekstowy w widoku alertów dla ios 8?
34
A
Odpowiedz
89
Zrzut
Kod
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Login"
message: @"Input username and password"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"name";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"password";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.secureTextEntry = YES;
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSArray * textfields = alertController.textFields;
UITextField * namefield = textfields[0];
UITextField * passwordfiled = textfields[1];
NSLog(@"%@:%@",namefield.text,passwordfiled.text);
}]];
[self presentViewController:alertController animated:YES completion:nil];
6
UIAlertView *myView = [[UIAlertView alloc]initWithTitle:@"Input" message:@"Enter your value" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
myView.alertViewStyle = UIAlertViewStylePlainTextInput;
[myView textFieldAtIndex:0].delegate = self;
[myView show];
można pokryć w ten sposób .Dzięki
3
UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Please enter someth" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av textFieldAtIndex:0].delegate = self;
[av show];
też, trzeba będzie wdrożyć UITe xtFieldDelegate, UIAlertViewDelegate protokołów.
a jeśli uialertcontroller użytkownik następnie użyć tego jeden
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Enter User Credentials"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do Some action here
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Username";
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Password";
textField.secureTextEntry = YES;
}];
[self presentViewController:alert animated:YES completion:nil];
5
AlertViewController
// use UIAlertController
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:@"Title"
message:@"SubTitle"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
//Do Some action here
UITextField *textField = alert.textFields[0];
NSLog(@"text was %@", textField.text);
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"placeHolderText";
textField.keyboardType = UIKeyboardTypeDefault;
}];
[self presentViewController:alert animated:YES completion:nil];
UIAlertView
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"SubTitle"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
[dialog show];
}
0
UIAlertViewController z wprowadzania tekstu
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// optionally configure the text field
textField.keyboardType = UIKeyboardTypeAlphabet;
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
UITextField *textField = [alert.textFields firstObject];
textField.placeholder = @"Enter Input";
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
3
Przykład realizacji z Swift 3:
var textField: UITextField?
// create alertController
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alertController.addTextField { (pTextField) in
pTextField.placeholder = "usefull placeholdr"
pTextField.clearButtonMode = .whileEditing
pTextField.borderStyle = .none
textField = pTextField
}
// create cancel button
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (pAction) in
alertController.dismiss(animated: true, completion: nil)
}))
// create Ok button
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (pAction) in
// when user taps OK, you get your value here
let inputValue = textField?.text
alertController.dismiss(animated: true, completion: nil)
}))
// show alert controller
self.present(alertController, animated: true, completion: nil)
0
Oto przydatna metoda z przedstawienia/anulować i obsługi zakończenie tekstu, jeśli wprowadzane:
/**
Presents an alert controller with a single text field for user input
- parameters:
- title: Alert title
- message: Alert message
- placeholder: Placeholder for textfield
- completion: Returned user input
*/
func showSubmitTextFieldAlert(title: String,
message: String,
placeholder: String,
completion: @escaping (_ userInput: String?) -> Void) {
let alertController = UIAlertController(title: title,
message: message,
preferredStyle: .alert)
alertController.addTextField { (textField) in
textField.placeholder = placeholder
textField.clearButtonMode = .whileEditing
}
let submitAction = UIAlertAction(title: "Submit", style: .default) { (action) in
let userInput = alertController.textFields?.first?.text
completion(userInput)
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in
completion(nil)
}
alertController.addAction(submitAction)
alertController.addAction(cancelAction)
present(alertController, animated: true)
}
Powiązane problemy
- 1. Jak zapobiegać obracaniu się alertów na zmianie orientacji IOS 8
- 2. Windows.h - Powiadomienie, gdy fokus wprowadzi wpis tekstowy
- 3. jak odczytać plik tekstowy w ios
- 4. Jak dodać wpis do historii muszli?
- 5. Efekt tekstowy 3D w iOS
- 6. Jak ukryć MasterView dla UISplitViewcontroller w systemów iOS 8
- 7. Jak dodać wpis w bazie danych strony podręcznika linuksowego?
- 8. Swift ios 8 zmienić tytuł czcionki w widoku tabeli
- 9. Niestandardowe odświeżanie dla systemu iOS 8 i iOS 9
- 10. Redux - Jak dodać wpis do tablicy w reduktorze
- 11. Jak dodać niewyraźne wyświetlenie widoku z widoku?
- 12. Jak dodać dwa strumienie w Java 8?
- 13. Nie można dodać wpis „0” buforować localClassSetAnalysis.bin
- 14. Czcionka systemowa dla systemu iOS 8 i iOS 9
- 15. iOS - Odbij animację tylko dla określonego widoku
- 16. Uniwersalny link w iOS 8?
- 17. jak dodać dwa kontrolery widoku w UIPageViewcontroller
- 18. Jak dodać tytuł sekcji w widoku UICollectionView?
- 19. Napisz plik tekstowy w dołączaniu (kodowany utf-8) w VB6
- 20. Zmiana odstępu między UIBarButtonItems w iOS 8
- 21. iOS 6 Wyjmij książka adresowa Wpis pozwolenie
- 22. Jak dodać UITabbarController do UIViewController w iOs
- 23. setHTTPBody w iOS 8 + Swift
- 24. Jak dodać wydarzenie w macierzystym kalendarzu IOS
- 25. Jak korzystać z UImageAsset w iOS 8
- 26. Jak zrobić UINavigationBar Transparent w IOS 8?
- 27. Otwórz kontroler widoku Safari z widoku tabeli na iOS 9 i otwórz w Safari na iOS 8 lub 7
- 28. Jak dodać "%" do danych w iOS-chart
- 29. Jak powodować nakładanie się alertów?
- 30. klienta w iOS 8 - Swift
'addTextFieldWithConfigurationHandler:'? – Larme