Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone IOS操作表按钮选择无法正常工作_Iphone_Uiactionsheet - Fatal编程技术网

Iphone IOS操作表按钮选择无法正常工作

Iphone IOS操作表按钮选择无法正常工作,iphone,uiactionsheet,Iphone,Uiactionsheet,您好,我正在开发使用actionsheet的小IOS应用程序。所以我的问题是这样的,当我在actionsheet外部单击时,它正在关闭我的actionsheet,它正在调用-(void)actionsheet:(UIActionSheet*)actionsheet clicked button Index:(NSInteger)buttonIndex方法,即使我没有单击actionsheet的任何按钮。它正在返回操作表按钮的lastindexof。那么如何避免这种情况呢。有解决办法吗?我尝试了-

您好,我正在开发使用actionsheet的小IOS应用程序。所以我的问题是这样的,当我在actionsheet外部单击时,它正在关闭我的actionsheet,它正在调用
-(void)actionsheet:(UIActionSheet*)actionsheet clicked button Index:(NSInteger)buttonIndex
方法,即使我没有单击actionsheet的任何按钮。它正在返回操作表按钮的lastindexof。那么如何避免这种情况呢。有解决办法吗?我尝试了
-(void)actionSheet:(UIActionSheet*)操作diddismisswithbuttonnindex:(NSInteger)buttonnindex

但结果仍然相同。

我自己编写时间选择器,而不是在iOS8中编写UIActionSheet:

date = [NSDate date];

timePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
timePicker.datePickerMode = UIDatePickerModeDateAndTime;
timePicker.hidden = NO;
timePicker.date = date;

displayFormatter = [[NSDateFormatter alloc] init];
[displayFormatter setTimeZone:[NSTimeZone localTimeZone]];
[displayFormatter setDateFormat:@"MM月dd日 EEE HH:mm"];

formatter = [[NSDateFormatter alloc] init];
[formatter setTimeZone:[NSTimeZone localTimeZone]];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

startDisplayTimeString = [displayFormatter stringFromDate:timePicker.date];
startTimeString = [formatter stringFromDate:timePicker.date];

NSTimeInterval interval = 24*60*60*1;
NSDate *endDate = [[NSDate alloc] initWithTimeIntervalSinceNow:interval];
endDisplayTimeString = [displayFormatter stringFromDate:endDate];
endTimeString = [formatter stringFromDate:endDate];

[_startTimeLabel setText:startDisplayTimeString];
[_endTimeLabel setText:endDisplayTimeString];

[pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES];

NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
pickerToolbar.tintColor = [UIColor whiteColor];
[pickerToolbar sizeToFit];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelBtnPressed:)];

[cancelBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorWithRed:253.0/255.0 green:68.0/255.0 blue:142.0/255.0 alpha:1.0],
                                   NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

UIBarButtonItem *titleButton;

float pickerMarginHeight = 168;


titleButton = [[UIBarButtonItem alloc] initWithTitle:@"title" style:UIBarButtonItemStylePlain target: nil action: nil];

[titleButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                     [UIColor colorWithRed:253.0/255.0 green:68.0/255.0 blue:142.0/255.0 alpha:1.0],
                                     NSForegroundColorAttributeName,
                                     nil] forState:UIControlStateNormal];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleDone target:self action:@selector(setTimePicker)];

[doneBtn setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                 [UIColor colorWithRed:253.0/255.0 green:68.0/255.0 blue:142.0/255.0 alpha:1.0],
                                 NSForegroundColorAttributeName,
                                 nil] forState:UIControlStateNormal];

NSArray *itemArray = [[NSArray alloc] initWithObjects:cancelBtn, flexSpace, titleButton, flexSpace, doneBtn, nil];

[pickerToolbar setItems:itemArray animated:YES];

if(iPad){

    [pickerToolbar setFrame:CGRectMake(0, 0, 320, 44)];

    UIViewController* popoverContent = [[UIViewController alloc] init];
    popoverContent.preferredContentSize = CGSizeMake(320, 216);
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
    popoverView.backgroundColor = [UIColor whiteColor];
    [popoverView addSubview:timePicker];
    [popoverView addSubview:pickerToolbar];
    popoverContent.view = popoverView;
    popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    [popoverController presentPopoverFromRect:CGRectMake(0, pickerMarginHeight, 320, 216) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

}else{

    timeBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-300, 320, 246)];
    [timeBackgroundView setBackgroundColor:[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0]];

    [timeBackgroundView addSubview:pickerToolbar];
    [timeBackgroundView addSubview:timePicker];

    [self.view addSubview:timeBackgroundView];}

当您点击UIActionSheet外部时,UIKit执行与点击取消按钮相同的操作。在
-(void)actionSheet:(UIActionSheet*)actionSheet Clicked buttonIndex:(NSInteger)buttonIndex中发送的
按钮索引是取消按钮索引。默认情况下,没有办法知道用户是否点击了UIActionSheet的外部。如果需要此功能,您必须编写自己的自定义操作表,或将外部点击处理为取消点击