简体   繁体   中英

how to set validation on button current title

hi i am new in iphone development,and i have task to develop the uibutton and picker relational application.

i have to develop the one view which have the button 1 uipicker view. when i run the application at that time the title of the button is blank. if the user directly click to submit the button at that time user will get the error message.

but i can get the error msg and my following code is not working it is submiting the form without checking the button text validation.

following is my code:

if ([btnPicker.currentTitle isEqualToString:@" "]) {

     UIAlertView *alertPicker = [[UIAlertView alloc] initWithTitle:@"Required" message:@"Please,Select Month & Date." delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
     [alertPicker show];
     NSLog(@"%@", alertPicker);
     [alertPicker release];
 }

Actually a blank string is an empty string @"" not a space @" " . You have to test an empty string like this,

[btnPicker.currentTitle isEqualToString:@""];
[btnPicker.currentTitle isEqualToString:@""];

or

if ([btnPicker.currentTitle length]==0)

Shouldn't it be [btnPicker.currentTitle isEqualToString:@""] ? String without the space?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM