2014年9月24日 星期三

Xcode 6.0.1 / iOS 8 UIAlertController

UIAlertControllerStyleAlert with Buttons

UIAlertController  *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
   
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel Action");
        }];
   
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Delete Action");
}];

[alertController addAction:cancelAction];
[alertController addAction:deleteAction];

[self presentViewController:alertController animated:YES completion:nil];

UIAlertControllerStyleActionSheet with PickerView

//title \n\n\n\n\n\n\n\n\n\n\n\n is for picker space
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n"
message:nil
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *doneAction = [UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
//doDoneAction()
}];
   
pickerSourceArray = sourceArray;

UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 10, 0, 0)];
picker.delegate = self;
picker.dataSource = self;

[picker setShowsSelectionIndicator:YES];
[picker selectRow:0 inComponent:0 animated:YES];

[alertController.view addSubview:picker];
[alertController addAction:doneAction];
[self.view bringSubviewToFront:picker];
[self presentViewController:alertController animated:YES completion:nil];

沒有留言:

張貼留言