简体   繁体   中英

iOS - alertView shouldEnableFirstButton

I want the user to not be able to click the cancel button on UIAlertView, yet I still want it to be there, but shaded out. I know a shouldEnableFirstButton function is there but it doesn't involve cancel button. Do you have any idea how to do it?

Thanks.

Use the following:

UIAlertView *vw = [[UIAlertView alloc] initWithTitle:@"Information" message:@"This is a message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
    [vw show];

So, essentially you are setting the "Cancel" as other button.

Now, the following will solve your problem:

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    return NO;
}

If you want to perform some action in OK button press you can always do that here:

- (void)alertViewCancel:(UIAlertView *)alertView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM