我正在使用一个文本输入的UIAlertView.
- UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Save" message:@"Please Enter the Name of PDF" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
- [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput]
当UITextField为空时,我想做什么我用代理功能禁用OK按钮
- - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
- {
- return NO;
- }
当用户开始在文本框中写入某些东西时,OK按钮应该被启用.
解决方法
请尝试这个
- - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
- {
- /* Retrieve a text field at an index -
- raises NSRangeException when textFieldIndex is out-of-bounds.
- The field at index 0 will be the first text field
- (the single field or the login field),The field at index 1 will be the password field. */
- /*
- 1> Get the Text Field in alertview
- 2> Get the text of that Text Field
- 3> Verify that text length
- 4> return YES or NO Based on the length
- */
- return [alertView textFieldAtIndex:0].text.length > 0;
- }