New Features of iOS8: UIAlertController
IOS8 combines many familiar controls.
For example, in this section: UIAlertController
UIAlertController integrates all functions of UIAlert/UIActionSheet
// Create the code: UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ prompt message: @ Ah ah preferredStyle: UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
PreferredStyle is an enumeration.
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) { UIAlertControllerStyleActionSheet = 0, UIAlertControllerStyleAlert } NS_ENUM_AVAILABLE_IOS(8_0);
However, no button is clicked in the pop-up box.
Therefore, button events must be added.
// Struct is a type enumeration // typedef NS_ENUM (NSInteger, UIAlertActionStyle) {// UIAlertActionStyleDefault = 0, // UIAlertActionStyleCancel, // optional //} struct (8_0 );
UIAlertAction * action = [UIAlertAction actionWithTitle: @ style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action) {// callback in the block // to do...}]; [alert addAction: action]; UIAlertAction * actionDelete = [UIAlertAction actionWithTitle: @ Delete style: UIAlertActionStyleDestructive handler: ^ (UIAlertAction * action) {// to do...}]; [alert addAction: actionDelete];
You can add a button, but what should you do in the Add input box?
Class provides a method:
-(Void) addTextFieldWithConfigurationHandler :( void (^) (UITextField * textField) configurationHandler;
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @11; }];You can set any attributes of textField in the block to be more flexible.
@ Property (nonatomic, readonly) NSArray * textFields; // obtain all input boxes