Ich möchte eine Alertview mit zwei uitextfields darin erstellen.So erstellen Sie zwei Textfelder in einer Alarmansicht, IOS
method:
//show alertview for file input
- (IBAction)showAddFiles:(id)sender {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter File Details"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add", nil];
UITextField *textFieldDescription = [message textFieldAtIndex:0];
textFieldDescription.placeholder = @"File Description : Ex. Acat Briefing";
UITextField *textFieldFileName = [message textFieldAtIndex:1];
textFieldFileName.placeholder = @"Exact File Name : Ex. acat.pdf";
[message show];
}
//make sure file description is long enoguh
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if([inputText length] <= 15 && [inputText length] >= 4)
{
return YES;
}
else
{
return NO;
}
}
//handle add button
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Add"])
{
UITextField *fileDescription = [alertView textFieldAtIndex:0];
UITextField *fileName = [alertView textFieldAtIndex:1];
NSLog(@"Desc: %@\nName: %@", fileDescription.text, fileName.text);
}
}
Fehler:
* app Beenden aufgrund abgefangene Ausnahme 'NSInvalidArgumentException', Grund: 'textFieldIndex (0) außerhalb der Grenzen des Arrays von Textfeldern'
Warum bekomme ich diesen Fehler, wie kann ich zwei uitextfields in einer Alert-Ansicht erstellen?
========= Arbeitslösung =========== Danke für die Antwort unten funktioniert, wenn Sie nur zwei Klartextfelder benötigen, ist
//show alertview for file input
- (IBAction)showAddFiles:(id)sender {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter File Details"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add", nil];
[message setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField *fileDescription = [message textFieldAtIndex:0];
[email protected]"Ex. acat.pdf";
[[message textFieldAtIndex:1] setSecureTextEntry:NO];
UITextField *fileName= [message textFieldAtIndex:1];
[email protected]"Ex. Acat Briefing";
[message show];
}
Versuchen Sie, die Textfeldzuweisung umzudrehen. Erstellen Sie zuerst ein Textfeld und dann [message textfieldatindex: 0] = newTextField – Hackmodford