我已经阅读了堆栈上的几个类似问题,但到目前为止似乎没有一个答案适合。因此,它一定是非常明显的事情,一旦得到答复,我将不得不鞭打自己。
该代码在 iPhone 上运行良好,但在 iPad 上运行良好,操作表几乎没有高度。没有工具栏,它是由普通的 UIButton 触发的。我已经考虑过弹出框,但是这是一个通用应用程序,因此我宁愿不要为 iPhone 和 iPad 重新编写相同的代码两次,并尝试使应用程序尽可能轻巧。
我试过 showFromRect 和 showFromTabbar。
谢谢
代码:
-(IBAction) setDateTime:(id) sender {
dateSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[dateSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 44, 0, 0);
UIDatePicker *appointmentDayPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[appointmentDayPicker setDatePickerMode:UIDatePickerModeDateAndTime];
[dateSheet addSubview:appointmentDayPicker];
[appointmentDayPicker release];
UIToolbar *controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, dateSheet.bounds.size.width, 44)];
[controlToolBar setBarStyle:UIBarStyleBlack];
[controlToolBar sizeToFit];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Set" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDateSet)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateSet)];
[controlToolBar setItems:[NSArray arrayWithObjects:spacer, cancelButton,setButton, nil] animated:NO];
[spacer release];
[setButton release];
[cancelButton release];
[dateSheet addSubview:controlToolBar];
[controlToolBar release];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[dateSheet showFromRect:CGRectMake(100,100, 320, 485) inView:self.view animated:YES];
[dateSheet setBounds:CGRectMake(0, 0, 200, 485)];
} else {
[dateSheet showInView:self.view];
[dateSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
}
编辑:添加图片