First off I am fairly new to xcode. I am trying to add multiple alerts to a single view. I am creating a form for an ipad which allows the users to enter in information into text boxes. Since there are multiple text boxes that are required to fill out, I don't want multiple alert boxes to pop up displaying every error, but instead I want one alert view to show multiple errors. the commented code down below is how I imagine it might be written
- (IBAction)showMessage:(id)sender {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Name" //"Address"
//if name=nil message:@"PLease fill out your name"
//if address=nilmessage:@"PLease fill out your address"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
*Is it possible to put if statements before and after the messages to be able to do this?
Do it like this:
- (IBAction)showMessage:(id)sender {
NSString *theMessage = @"";
if (textField.text.length == 0) {
theMessage = @"hey";
} else if (textField2.text.length == 0) {
theMessage = @"hey2";
} else if (textField.text.length == 0) && (textField2.text.length == 0) {
theMessage = @"doubleHey";
}
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Name"
message:theMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[message release];
}