码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 8 & Xcode 6:UIAlertView取消时不回调alertViewCancel:

时间:2014-11-19 13:58:19      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

在做UIAlertView取消操作时,发现委托函数alertViewCancel:并不被调用,只好在alertView: didDismissWithButtonIndex:中进行判断。

 1 @interface DateViewController () <UIAlertViewDelegate>
 2 @property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;
 3 
 4 @end
 5 
 6 @implementation DateViewController
 7 
 8 - (void)viewDidLoad {
 9     [super viewDidLoad];
10     NSDate *now = [NSDate date];
11     [self.datePicker setDate:now animated:NO];
12 }
13 
14 - (void)didReceiveMemoryWarning {
15     [super didReceiveMemoryWarning];
16     // Dispose of any resources that can be recreated.
17 }
18 
19 - (IBAction)buttonPress:(UIButton *)sender {
20     NSDate *selectedDate = self.datePicker.date;
21     NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
22     fmt.dateFormat = @"yyyy - MM - dd";
23 
24     NSString *string = [NSString stringWithFormat:@"You selecte %@", [fmt stringFromDate:selectedDate]];
25     UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Date Picker"
26                                                    message:string
27                                                   delegate:self
28                                          cancelButtonTitle:@"Cancel"
29                                          otherButtonTitles:@"OK", nil];
30     [view show];
31 }
32 
33 - (void)alertViewCancel:(UIAlertView *)alertView {
34     NSLog(@"View canceled.");
35 }
36 
37 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
38     NSLog(@"buttonIndex = %zi", buttonIndex);
39 }
40 
41 @end

日志输出如下,取消按钮序号为0,其他按钮序号按添加次序递增。

bubuko.com,布布扣

iOS 8 & Xcode 6:UIAlertView取消时不回调alertViewCancel:

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/michaellfx/p/4108033.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!