任何人都可以帮助我防止 alertview 在其按钮单击事件中被解雇吗??
我有一个 textview 作为我的 alertView 的 subview ,如果 textview 的值为 nil,我不想关闭它。
最佳答案
因为这是一个非常老的问题,但我有一个解决方案,如果其他开发人员在不久的将来需要的话,我会发布。
在.h文件中实现协议(protocol)方法
为了响应 UIAlertView 中的按钮点击,我们将使用 – alertView:clickedButtonAtIndex: 协议(protocol)方法作为
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
//Now below code will check if uitextfield value.
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] > 0)
{
//text field value is greater than zero ,then Done button will appear as blue,or else it will be blurred
return YES;
}
else
{
return NO;
}
}
或者,还有一种更快的方法:
return [inputText length] ? YES : NO;
与 if 语句
做同样的事情。
关于objective-c - 防止 AlertView 解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802709/