2011-07-13 12 views
2
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]; 
} 

上記のコードには、8つのテキストフィールドがあります。そのためには、すべてのテキストフィールドが空である状態を定義する必要があります。それが働いています。しかし、誰かが空白のテキストフィールドを持っているように私が定義すると、警告表示も表示されますが、表示されません。問題は、整数値「0」を入力すると警告表示も表示されますが、「0」の値が表示されないようにすることです。 picke4rビューで選択された値。どのようにコードを設定しますか?テキストフィールドの設定条件。テキスト?

答えて

2

試してみてください。

if([txtName.text length] == 0 || [txtName.text isEqualToString:@""]) 
{ 
     // Alert here 
} 

テスト長さ0または空の文字列に文字列を比較します。

+2

第2の比較は冗長です。 'NSString'は長さが0の場合にのみ' '' 'と等しくなります。 –

0

このように0を比較することができます。

if ([txtName.text isEqualToString:@"0"]) { 
    // 0 
} 
0

チェックあなたのテキストフィールド内の文字列の長さが0の場合:テキストフィールドに全く入力されたものがない場合

if ([txtField1.text length] == 0) { 
    //your stuff here 
} 

これがまさに当てはまるだろう。 nilNULLの間の「区別」はもう必要ありません。

1

テキストフィールドが空白の場合は、最初の条件は必要ありません。警告が表示されます。 この

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]; 
} 
0

([txtName.text isEqualToString:@ ""])場合試し

{

}

関連する問題