ios – 禁用UIAlertView按钮

前端之家收集整理的这篇文章主要介绍了ios – 禁用UIAlertView按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用一个文本输入的UIAlertView.
  1. UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Save" message:@"Please Enter the Name of PDF" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
  2. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput]

当UITextField为空时,我想做什么我用代理功能禁用OK按钮

  1. - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
  2. {
  3.  
  4. return NO;
  5. }

用户开始在文本框中写入某些东西时,OK按钮应该被启用.

解决方法

请尝试这个
  1. - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
  2. {
  3. /* Retrieve a text field at an index -
  4. raises NSRangeException when textFieldIndex is out-of-bounds.
  5.  
  6. The field at index 0 will be the first text field
  7. (the single field or the login field),The field at index 1 will be the password field. */
  8.  
  9. /*
  10. 1> Get the Text Field in alertview
  11.  
  12. 2> Get the text of that Text Field
  13.  
  14. 3> Verify that text length
  15.  
  16. 4> return YES or NO Based on the length
  17. */
  18.  
  19. return [alertView textFieldAtIndex:0].text.length > 0;
  20.  
  21. }

猜你在找的iOS相关文章