为什么看不到按钮?

时间:2013-07-30 12:10:42

标签: ios objective-c

任务是选择文本字段的日期。开发在iPad上,所以我使用UIPopover。但我需要两个顶部的按钮。我正在尝试这样做,但按钮不会显示。可能是什么问题?

请看截图:

enter image description here

完整代码:

dateSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[dateSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 44, 0, 0);
UIDatePicker *dayPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[dayPicker setDatePickerMode:UIDatePickerModeDate];
[dateSheet addSubview:dayPicker];
[dayPicker release];

UIToolbar *controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, dateSheet.bounds.size.width, 44)];
[controlToolBar setBarStyle:UIBarStyleBlackTranslucent];
[controlToolBar sizeToFit];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton;
setButton = [[UIBarButtonItem alloc] initWithTitle:@"Установить" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDateStart:)];
setButton.tag = pTag;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Отменить" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateStart)];
[controlToolBar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO];
[spacer release];
[setButton release];
[cancelButton release];



UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
popoverView.backgroundColor = [UIColor whiteColor];

dateSheet.frame = CGRectMake(0, 0, 320, 344);

[popoverView addSubview:dateSheet];
[popoverView addSubview:controlToolBar];
popoverContent.view = popoverView;

popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

[popoverController presentPopoverFromRect:changeDateStartField.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverView release];
[popoverContent release];

1 个答案:

答案 0 :(得分:1)

你应该改变

UIBarButtonSystemItemFlexibleSpace

UIBarButtonSystemItemFixedSpace
间隔按钮的