iPad框架上的UIActionSheet太小 [英] UIActionSheet on iPad frame too small
问题描述
我试图在iPad上显示 UIActionSheet
,其中包含 UIPickerView
,我有等效代码工作在iPhone,所以我的 UIPickerView
委托和数据源的东西工作,但在iPad上,当我使用 - [UIActionSheet showFromRect:inView:animated: code>结果
UIPopover
/ UIActionSheet
太小了,我似乎无法设置框架大小,也没有显示任何按钮。
I am trying to display a UIActionSheet
on the iPad with a UIPickerView
in it, I have the equivalent code working for iPhone so my UIPickerView
delegate and datasource stuff work, but on the iPad when I use -[UIActionSheet showFromRect:inView:animated:]
the result UIPopover
/UIActionSheet
is way too small and I can not seem to set the frame size, also none of the buttons are displayed.
我不知道这是因为他们在界限之外还是有其他事情发生。这是我的代码看起来像我已删除所有非基本代码(iPhone等)。是否有人知道我在做什么错误,任何人都知道任何例子。
I don't know if this is because they are outside the bounds or there is something else going on. This is what my code looks like after I have removed all non-essential code (iPhone etc). Does anybody know what I am doing wrong, does anybody know of any examples.
CGRect thePickerFrame = CGRectMake(0, 0, 320.0, 485.0);
UIPickerView * thePickerView = [[UIPickerView alloc] initWithFrame:thePickerFrame];
[pickerActionSheet release], pickerActionSheet =
[[UIActionSheet alloc] initWithTitle:@"Choose" delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Next", nil];
thePickerView.showsSelectionIndicator = YES;
thePickerView.dataSource = self;
thePickerView.delegate = self;
[pickerActionSheet addSubview:thePickerView];
[thePickerView selectRow:0 inComponent:0 animated:NO];
[thePickerView release];
[pickerActionSheet showFromRect:currentTextField.bounds
inView:currentTextField animated:NO];
pickerActionSheet.frame = thePickerFrame;
推荐答案
我认为UIActionSheet不可调整大小,在你的代码中, [pickerActionSheet addSubview:thePickerView];
行,你会看到ActionSheet完全适合按钮。
I think that UIActionSheet is not resizable, try to comment in your code the line with [pickerActionSheet addSubview:thePickerView];
and you will see that the ActionSheet fits perfecly to the buttons.
我会推荐一个具有自定义 UIViewController
的 UIPopoverController
。类似这样:
I would recommend a UIPopoverController
with a custom UIViewController
. Something like this:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleDefault;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(BACK_ACTION:)];
UIBarButtonItem *chooseButton = [[UIBarButtonItem alloc] initWithTitle:@"Choose" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(NEXT_ACTION:)];
UIBarButtonItem *fixed1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *fixed2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolbar setItems:[NSArray arrayWithObjects:cancelButton, fixed1, chooseButton, fixed2, nextButton, nil]];
UIPickerView *thePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
CGRect thePickerFrame = thePickerView.frame;
thePickerFrame.origin.y = toolbar.frame.size.height;
[thePickerView setFrame:thePickerFrame];
UIView *view = [[UIView alloc] init];
[view addSubview:thePickerView];
[view addSubview:toolbar];
UIViewController *vc = [[UIViewController alloc] init];
[vc setView:view];
[vc setContentSizeForViewInPopover:CGSizeMake(320, 260)];
popover = [[UIPopoverController alloc] initWithContentViewController:vc];
thePickerView.showsSelectionIndicator = YES;
thePickerView.dataSource = self;
thePickerView.delegate = self;
[thePickerView selectRow:0 inComponent:0 animated:NO];
[popover presentPopoverFromRect:currentTextField.bounds inView:currentTextField permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
其中popover是在.h中声明的类变量( UIPopoverController * popover;
Where popover is a class variable declared in .h (UIPopoverController *popover;
).
顺便说一句,我使用ARC,所以代码中没有发布。
By the way, I'm using ARC, so there is no release in the code.
这篇关于iPad框架上的UIActionSheet太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!