我想要做的,如果UITextField
上沒有任何內容,應用程序將顯示警報。我不明白我在做什麼錯。這裏是我的代碼:如果UITextField爲空,則顯示UIAlert
- (IBAction)Calculate:(id)sender {
/*If there is nothing on textfield, it will show an alert*/
if ([addtake.text length] && [Subtake.text length] == 0)
{
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Alert"message:@"Empty TextField not allowed" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil];
[myAlert show];
}
else{
NSString *Adding =[addtake text];
NSInteger number = [Adding intValue]; /*Converting String to int*/
NSInteger new = 5 + number;
NSString *newString = [NSString stringWithFormat:@"%d",new];
[myAdd setText:newString];
/*Subtruct*/
NSString *Subtruct =[Subtake text];
NSInteger SubNumber = [Subtruct intValue];
NSInteger newSub = 10 - SubNumber;
NSString *newSubString = [NSString stringWithFormat:@"%d",newSub];
[mySub setText:newSubString];
[addtake resignFirstResponder];
[Subtake resignFirstResponder];
}
}
其中textField?吸收或吸收? – Shmidt