gpt4 book ai didi

ios - 禁用 UIAlertView 按钮

转载 作者:技术小花猫 更新时间:2023-10-29 10:29:38 26 4
gpt4 key购买 nike

我正在制作一个带有文本输入的 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 为空时我想做什么我用委托(delegate)函数禁用 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;

}

关于ios - 禁用 UIAlertView 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17747106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com