Prevent AlertView dismissal

走远了吗. 提交于 2020-01-03 20:14:58

问题


Can anyone help me in preventing dismissal of alertview on its button click event??

I have a textview as a subview of my alertView and i dont want to dismiss it if textview's value is nil.


回答1:


That might be against HIG Guidelines to NOT to dismiss an UIAlertView.

WORKAROUND : I don't know what goes on in your app, but to acheive this thing, what you could do is dismiss the AlertView and then check if textView's text is set or not. If it is set to nil, then bring up the alertview again!




回答2:


As this is very old question,but I got one solution and though of posting if any other developer need in near future.

Implement protocol methods in .h file

In order to respond to button taps in our UIAlertView, we will use the – alertView:clickedButtonAtIndex: protocol method as

- (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;
    }
}

Alternately, there is a much faster approach:

return [inputText length] ? YES : NO;

The does the same thing as the if statement does.




回答3:


i'm not sure you can.

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView

is the only option available on callBack. And there's still at least one active button.

If you really need that specific behavior, try reimplementing your own UIAlertView



来源:https://stackoverflow.com/questions/12802709/prevent-alertview-dismissal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!