Alert Delegates
Need to know if a user tapped OK or Cancel? Alerts use delegates to recover user choices after they’ve been made, using a simple callback. Delegates should declare the UIAlertViewDelegate protocol. In normal use, you often set the delegate to your primary (active) view controller object.
Delegate methods enable you to react as different buttons are pressed. As you’ve already seen, you can omit that delegate support if all you need to do is show some message with an OK button.
After the user has seen and interacted with your alert, the delegate receives an alertView:clickedButtonAtIndex: callback. The second parameter passed to this method indicates which button was pressed. Button numbering begins with zero. The Cancel button ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access