简体   繁体   English

如何在按钮当前标题上设置验证

[英]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.嗨,我是 iphone 开发新手,我的任务是开发 uibutton 和选择器相关应用程序。

i have to develop the one view which have the button 1 uipicker view.我必须开发一个具有按钮 1 uipicker 视图的视图。 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:@""] ?不应该是[btnPicker.currentTitle isEqualToString:@""]吗? String without the space?没有空格的字符串?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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