Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buttonIndex in UIAlertController #9

Closed
qiaoyan opened this issue Apr 4, 2018 · 2 comments
Closed

buttonIndex in UIAlertController #9

qiaoyan opened this issue Apr 4, 2018 · 2 comments

Comments

@qiaoyan
Copy link

qiaoyan commented Apr 4, 2018

buttonIndex = -1 when click cancel button, buttonIndex = 0 when click other button. So current workaround way is [buttonIndex+1]

[UIAlertController KDI_presentAlertControllerWithTitle:@"Sign Out?" message:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@[@"Sign Out"] completion:^(__kindof UIAlertController * _Nonnull alertController, NSInteger buttonIndex) {
if (alertController.actions[buttonIndex+1].style != UIAlertActionStyleCancel) {
//do something
}
}];

@willbur1984
Copy link
Member

What specifically is the issue? If you want to know whether the cancel button was tapped check for KDIUIAlertControllerCancelButtonIndex within the completion block.

if (buttonIndex == KDIUIAlertControllerCancelButtonIndex) {
    // cancel button was tapped
}
else {
    // check other indexes, starting at 0 - (count of other titles - 1)
}

@qiaoyan
Copy link
Author

qiaoyan commented Apr 8, 2018

understood..

@qiaoyan qiaoyan closed this as completed Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants