Why the button in the action sheet is not work?
I try to add a date picker in action sheet , also give another b开发者_开发问答utton
It looks like the image
I can get the time when I roll the picker
But that small Done button not work...
I can't even to touch it.
This is my code ,not too much ...
I can't figure why the button not working ?
- (IBAction)selectDate:(id)sender{
menu = [[UIActionSheet alloc] initWithTitle:@"Select Date"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[menu setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
startPickerView = [[UIDatePicker alloc] init];
startPickerView.datePickerMode = UIDatePickerModeTime;
[menu sendSubviewToBack:startPickerView];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320,460)];
CGRect pickerRect = startPickerView.bounds;
pickerRect.origin.y = -60;
startPickerView.bounds = pickerRect;
[startPickerView addTarget:self action:@selector(timeChange:) forControlEvents:UIControlEventValueChanged];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventTouchUpInside];
[menu addSubview:startPickerView];
[menu addSubview:closeButton];
[closeButton release];
[menu release];
[startPickerView release];
}
Many thanks for any reply~
Webber
I've did something similar to this before using the below code. Here I create a date pickerview and add to an action sheet with two buttons: Done and Cancel in a toolbar.
- (IBAction)selectDate:(id)sender{
UIActionSheet *pickerViewPopup = [[UIActionSheet alloc] init];
const CGFloat toolbarHeight = 44.0f;
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, toolbarHeight, 0, 0)];
pickerView.datePickerMode = UIDatePickerModeDate;
pickerView.hidden = NO;
pickerView.date = [NSDate date];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, toolbarHeight)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];
[barItems addObject:doneBtn];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
[barItems addObject:cancelBtn];
[pickerToolbar setItems:barItems animated:YES];
[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:pickerView];
[pickerViewPopup showInView:self.view];
[pickerViewPopup setBounds:CGRectMake(0,0,self.view.frame.size.width, 464)];
}
An example of where this is used can be found at: http://www.buggyprogrammer.co.uk/2010/08/18/open-uipickerview-when-user-enters-textfield/
I think the way you use the UIActionSheet is the source for your problems : a UIActionSheet listens for events on the buttons on the sheet .. and the way you are using it you overlay it with your own components.
I would personally create a custom UIView and show that instead of putting the DatePicker and the Done button on top of a UIActionSheet.
精彩评论