how set condition for text field. text?
if([txtField1.text intValue] == nil && [txtField2.text intValue] == nil && [txtField3.text intValue] == nil && [txtField4.text intValue] == nil && [txtField5.text intValue] == nil && [txtField6.text intValue] == nil && [txtField7.text intValue] == nil && [txtField8.text intValue] == nil )
{
UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message: @"Please complete your test." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[info show];
[info release];
}
else if(txtField1.text == NULL || txtField2.text == NULL || txtField3.text == NULL || txtField4.text == NULL || txtField5.text == NULL || txtField6.text == NULL ||txtField7.text == NULL || txtField8.text == NULL )
{
UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message: @"Please complete your test." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[info show];
[info release];
}
else{
fourthScreen=[[FourthScreen alloc] initWithNibName:@"FourthScreen" bundle:nil];
[self.navigationController pushViewController:self.fourthScreen animated:YES];
}
in above code i hav开发者_C百科e 8 text field. for that i have define a condition that is when all text field is blank of nil the show alert view msg. and it is working. But when i define as like when any one has nil or blank text field the also show alert view but it not show. The problem is that when i enter integer value"0" then it also show alert view but i want that it not show for '0' value. The value chosen by picke4r view. how set the code for that?
Try:
if([txtName.text length] == 0 || [txtName.text isEqualToString:@""])
{
// Alert here
}
Test length to 0 or compare string to a blank string.
No need for first condition any way if any text field is empty alert should prompt up. Try this
if([txtField1.text length] == 0 || [txtField2.text length] == 0 || [txtField3.text length] == 0 || [txtField4.text length == 0] || [txtField5.text length] == 0 || [txtField6.text length == 0 ||[txtField7.text length] == 0 || [txtField8.text length] == 0 )
{
UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message: @"Please complete your test." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[info show];
[info release];
}
else{
fourthScreen=[[FourthScreen alloc] initWithNibName:@"FourthScreen" bundle:nil];
[self.navigationController pushViewController:self.fourthScreen animated:YES];
}
you can compare 0 like this.
if ([txtName.text isEqualToString:@"0"]) {
// 0
}
Check if the length of the String in your textFields is 0:
if ([txtField1.text length] == 0) {
//your stuff here
}
This will hold true exactly if there is nothing entered at all in the text field. You will not need the "distinction" between nil
and NULL
anymore.
if ([txtName.text isEqualToString:@""])
{
}
精彩评论